Select a new primary node when closing the current one

The new primary node can be any non-locked leaf node that isn't already 
primary.
This commit is contained in:
Guldoman 2021-10-23 03:34:24 +02:00
parent 6f732f67f9
commit 331b8e90ec
No known key found for this signature in database
GPG Key ID: C08A498EC7F1AFDD
1 changed files with 27 additions and 2 deletions

View File

@ -149,10 +149,17 @@ function Node:remove_view(root, view)
else else
locked_size = locked_size_y locked_size = locked_size_y
end end
if self.is_primary_node or locked_size then local next_primary
if self.is_primary_node then
next_primary = core.root_view:select_next_primary_node()
end
if locked_size or (self.is_primary_node and not next_primary) then
self.views = {} self.views = {}
self:add_view(EmptyView()) self:add_view(EmptyView())
else else
if other == next_primary then
next_primary = parent
end
parent:consume(other) parent:consume(other)
local p = parent local p = parent
while p.type ~= "leaf" do while p.type ~= "leaf" do
@ -160,7 +167,7 @@ function Node:remove_view(root, view)
end end
p:set_active_view(p.active_view) p:set_active_view(p.active_view)
if self.is_primary_node then if self.is_primary_node then
p.is_primary_node = true next_primary.is_primary_node = true
end end
end end
end end
@ -823,6 +830,24 @@ function RootView:get_primary_node()
end end
local function select_next_primary_node(node)
if node.is_primary_node then return end
if node.type ~= "leaf" then
return select_next_primary_node(node.a) or select_next_primary_node(node.b)
else
local lx, ly = node:get_locked_size()
if not lx and not ly then
return node
end
end
end
function RootView:select_next_primary_node()
return select_next_primary_node(self.root_node)
end
function RootView:open_doc(doc) function RootView:open_doc(doc)
local node = self:get_active_node_default() local node = self:get_active_node_default()
for i, view in ipairs(node.views) do for i, view in ipairs(node.views) do