Fix error when opening the first document if project view was active
This commit is contained in:
parent
edaa8fb42b
commit
7a856be6e4
|
@ -396,14 +396,33 @@ function RootView:get_active_node()
|
|||
return self.root_node:get_node_for_view(core.active_view)
|
||||
end
|
||||
|
||||
-- Get un unlocked node with at least one view.
|
||||
local function get_node_unlocked(node)
|
||||
if not node.locked and #node.views > 0 then
|
||||
return node
|
||||
end
|
||||
if node.type ~= "leaf" then
|
||||
local a = get_node_unlocked(node.a)
|
||||
if a then return a end
|
||||
return get_node_unlocked(node.b)
|
||||
end
|
||||
end
|
||||
|
||||
function RootView:get_document_view()
|
||||
local node = get_node_unlocked(self.root_node)
|
||||
if node then
|
||||
return node.views[1]
|
||||
end
|
||||
end
|
||||
|
||||
function RootView:open_doc(doc)
|
||||
local node = self:get_active_node()
|
||||
if node.locked and core.last_active_view then
|
||||
core.set_active_view(core.last_active_view)
|
||||
if node.locked then
|
||||
local default_view = self:get_document_view()
|
||||
assert(default_view, "Cannot find an unlocked node to open the document.")
|
||||
core.set_active_view(default_view)
|
||||
node = self:get_active_node()
|
||||
end
|
||||
assert(not node.locked, "Cannot open doc on locked node")
|
||||
for i, view in ipairs(node.views) do
|
||||
if view.doc == doc then
|
||||
node:set_active_view(node.views[i])
|
||||
|
|
Loading…
Reference in New Issue