Use get_primary_node instead of Rootview:get_primary_view

This commit is contained in:
Francesco Abbate 2020-12-14 14:19:28 +01:00
parent d18eef4ef0
commit 499f085045
2 changed files with 8 additions and 11 deletions

View File

@ -264,7 +264,7 @@ function core.init()
core.command_view = CommandView() core.command_view = CommandView()
core.status_view = StatusView() core.status_view = StatusView()
core.root_view.root_node.is_primary_view = true core.root_view.root_node.is_primary_node = true
core.root_view.root_node:split("down", core.command_view, true) core.root_view.root_node:split("down", core.command_view, true)
core.root_view.root_node.b:split("down", core.status_view, true) core.root_view.root_node.b:split("down", core.status_view, true)

View File

@ -399,7 +399,7 @@ function Node:close_all_docviews()
i = i + 1 i = i + 1
end end
end end
if #self.views == 0 and self.is_primary_view then if #self.views == 0 and self.is_primary_node then
self:add_view(EmptyView()) self:add_view(EmptyView())
end end
else else
@ -434,26 +434,23 @@ function RootView:get_active_node()
return self.root_node:get_node_for_view(core.active_view) return self.root_node:get_node_for_view(core.active_view)
end end
local function get_primary_view(node) local function get_primary_node(node)
if node.is_primary_view then if node.is_primary_node then
return node return node
end end
if node.type ~= "leaf" then if node.type ~= "leaf" then
return get_primary_view(node.a) or get_primary_view(node.b) return get_primary_node(node.a) or get_primary_node(node.b)
end end
end end
function RootView:get_primary_view() function RootView:get_primary_node()
local node = get_primary_view(self.root_node) return get_primary_node(self.root_node)
if node then
return node.views[1]
end
end end
function RootView:open_doc(doc) function RootView:open_doc(doc)
local node = self:get_active_node() local node = self:get_active_node()
if node.locked then if node.locked then
local default_view = self:get_primary_view() local default_view = self:get_primary_node().views[1]
assert(default_view, "internal error: cannot find original document node.") assert(default_view, "internal error: cannot find original document node.")
core.set_active_view(default_view) core.set_active_view(default_view)
node = self:get_active_node() node = self:get_active_node()