Merge pull request #625 from Guldoman/allow_closing_primary

Select a new primary node when closing the current one
This commit is contained in:
Adam 2021-11-07 15:10:19 -05:00 committed by GitHub
commit 40f698e4bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 2 deletions

View File

@ -149,10 +149,17 @@ function Node:remove_view(root, view)
else
locked_size = locked_size_y
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:add_view(EmptyView())
else
if other == next_primary then
next_primary = parent
end
parent:consume(other)
local p = parent
while p.type ~= "leaf" do
@ -160,7 +167,7 @@ function Node:remove_view(root, view)
end
p:set_active_view(p.active_view)
if self.is_primary_node then
p.is_primary_node = true
next_primary.is_primary_node = true
end
end
end
@ -823,6 +830,24 @@ function RootView:get_primary_node()
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)
local node = self:get_active_node_default()
for i, view in ipairs(node.views) do