Fix treesize toggle command and transition

This commit is contained in:
Francesco Abbate 2021-02-15 12:18:43 +01:00
parent b836c2e1e6
commit ebba21310b
2 changed files with 31 additions and 14 deletions

View File

@ -92,18 +92,23 @@ end
local type_map = { up="vsplit", down="vsplit", left="hsplit", right="hsplit" }
-- The "locked" argument below should be in the form {x = <boolean>, y = <boolean>}
-- and it indicates if the node want to have a fixed size along the axis where the
-- boolean is true. If not it will be expanded to take all the available space.
-- The "resizable" flag indicates if, along the "locked" axis the node can be resized
-- by the user.
function Node:split(dir, view, locked, resizable)
assert(type(locked) == 'table')
assert(self.type == "leaf", "Tried to split non-leaf node")
local type = assert(type_map[dir], "Invalid direction")
local node_type = assert(type_map[dir], "Invalid direction")
local last_active = core.active_view
local child = Node()
child:consume(self)
self:consume(Node(type))
self:consume(Node(node_type))
self.a = child
self.b = Node()
if view then self.b:add_view(view) end
if locked then
assert(type(locked) == 'table')
self.b.locked = locked
self.b.resizable = resizable or false
core.set_active_view(last_active)
@ -451,8 +456,11 @@ end
function Node:resize(axis, value)
if self.type == 'leaf' then
-- FIXME: repeated logic with Node:is_resizable()
if not self.locked or not self.locked[axis] or self.resizable then
-- The logic here is: accept the resize only if locked along the axis
-- and is declared "resizable". If it is not locked we don't accept the
-- resize operation here because for proportional panes the resize is
-- done using the "divider" value of the parent node.
if (self.locked and self.locked[axis]) and self.resizable then
local view = self.active_view
view.size[axis] = value
return true

View File

@ -23,7 +23,7 @@ function TreeView:new()
TreeView.super.new(self)
self.scrollable = true
self.visible = true
self.init_size = true
self.init_size = config.treeview_size
self.cache = {}
self.last = {}
end
@ -184,13 +184,15 @@ end
function TreeView:update()
-- update width
local dest = self.visible and config.treeview_size or 0
if self.init_size then
self.size.x = dest
self.init_size = false
-- FIXME: bring back the visibility toggle and animation
-- else
-- self:move_towards(self.size, "x", dest)
self.size.x = self.init_size
self.init_size = nil
elseif self.goto_size then
if self.goto_size ~= self.size.x then
self:move_towards(self.size, "x", self.goto_size)
else
self.goto_size = nil
end
end
TreeView.super.update(self)
@ -263,8 +265,15 @@ end
-- register commands and keymap
command.add(nil, {
["treeview:toggle"] = function()
view.visible = not view.visible
if view.visible then
view.previous_size = view.size.x
view.visible = false
view.goto_size = 0
else
view.visible = true
view.goto_size = view.previous_size
end
end,
})
keymap.add { ["ctrl+\\"] = "treeview:toggle" }
keymap.add { ["ctrl+t"] = "treeview:toggle" }