Merge pull request #625 from Guldoman/allow_closing_primary
Select a new primary node when closing the current one
This commit is contained in:
commit
40f698e4bf
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue