Fix treesize toggle command and transition
This commit is contained in:
parent
b836c2e1e6
commit
ebba21310b
|
@ -92,18 +92,23 @@ end
|
||||||
|
|
||||||
local type_map = { up="vsplit", down="vsplit", left="hsplit", right="hsplit" }
|
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)
|
function Node:split(dir, view, locked, resizable)
|
||||||
assert(type(locked) == 'table')
|
|
||||||
assert(self.type == "leaf", "Tried to split non-leaf node")
|
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 last_active = core.active_view
|
||||||
local child = Node()
|
local child = Node()
|
||||||
child:consume(self)
|
child:consume(self)
|
||||||
self:consume(Node(type))
|
self:consume(Node(node_type))
|
||||||
self.a = child
|
self.a = child
|
||||||
self.b = Node()
|
self.b = Node()
|
||||||
if view then self.b:add_view(view) end
|
if view then self.b:add_view(view) end
|
||||||
if locked then
|
if locked then
|
||||||
|
assert(type(locked) == 'table')
|
||||||
self.b.locked = locked
|
self.b.locked = locked
|
||||||
self.b.resizable = resizable or false
|
self.b.resizable = resizable or false
|
||||||
core.set_active_view(last_active)
|
core.set_active_view(last_active)
|
||||||
|
@ -451,8 +456,11 @@ end
|
||||||
|
|
||||||
function Node:resize(axis, value)
|
function Node:resize(axis, value)
|
||||||
if self.type == 'leaf' then
|
if self.type == 'leaf' then
|
||||||
-- FIXME: repeated logic with Node:is_resizable()
|
-- The logic here is: accept the resize only if locked along the axis
|
||||||
if not self.locked or not self.locked[axis] or self.resizable then
|
-- 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
|
local view = self.active_view
|
||||||
view.size[axis] = value
|
view.size[axis] = value
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -23,7 +23,7 @@ function TreeView:new()
|
||||||
TreeView.super.new(self)
|
TreeView.super.new(self)
|
||||||
self.scrollable = true
|
self.scrollable = true
|
||||||
self.visible = true
|
self.visible = true
|
||||||
self.init_size = true
|
self.init_size = config.treeview_size
|
||||||
self.cache = {}
|
self.cache = {}
|
||||||
self.last = {}
|
self.last = {}
|
||||||
end
|
end
|
||||||
|
@ -184,13 +184,15 @@ end
|
||||||
|
|
||||||
function TreeView:update()
|
function TreeView:update()
|
||||||
-- update width
|
-- update width
|
||||||
local dest = self.visible and config.treeview_size or 0
|
|
||||||
if self.init_size then
|
if self.init_size then
|
||||||
self.size.x = dest
|
self.size.x = self.init_size
|
||||||
self.init_size = false
|
self.init_size = nil
|
||||||
-- FIXME: bring back the visibility toggle and animation
|
elseif self.goto_size then
|
||||||
-- else
|
if self.goto_size ~= self.size.x then
|
||||||
-- self:move_towards(self.size, "x", dest)
|
self:move_towards(self.size, "x", self.goto_size)
|
||||||
|
else
|
||||||
|
self.goto_size = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
TreeView.super.update(self)
|
TreeView.super.update(self)
|
||||||
|
@ -263,8 +265,15 @@ end
|
||||||
-- register commands and keymap
|
-- register commands and keymap
|
||||||
command.add(nil, {
|
command.add(nil, {
|
||||||
["treeview:toggle"] = function()
|
["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,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
keymap.add { ["ctrl+\\"] = "treeview:toggle" }
|
keymap.add { ["ctrl+t"] = "treeview:toggle" }
|
||||||
|
|
Loading…
Reference in New Issue