refacto: sort actions declaration, remove close from main file
fixes #921 - use view.close instead of nvim-tree.close - put preview code inside the execution logic on keypress - sort keys in keypress_funcs - remove empty buffer when hijacking window
This commit is contained in:
@@ -54,40 +54,31 @@ local function go_to(mode)
|
||||
end
|
||||
|
||||
local keypress_funcs = {
|
||||
create = require'nvim-tree.actions.create-file'.fn,
|
||||
remove = require'nvim-tree.actions.remove-file'.fn,
|
||||
rename = require'nvim-tree.actions.rename-file'.fn(false),
|
||||
full_rename = require'nvim-tree.actions.rename-file'.fn(true),
|
||||
copy = require'nvim-tree.actions.copy-paste'.copy,
|
||||
close = view.close,
|
||||
close_node = require'nvim-tree.actions.movements'.parent_node(true),
|
||||
copy_absolute_path = require'nvim-tree.actions.copy-paste'.copy_absolute_path,
|
||||
copy_name = require'nvim-tree.actions.copy-paste'.copy_filename,
|
||||
copy_path = require'nvim-tree.actions.copy-paste'.copy_path,
|
||||
copy_absolute_path = require'nvim-tree.actions.copy-paste'.copy_absolute_path,
|
||||
copy = require'nvim-tree.actions.copy-paste'.copy,
|
||||
create = require'nvim-tree.actions.create-file'.fn,
|
||||
cut = require'nvim-tree.actions.copy-paste'.cut,
|
||||
dir_up = require'nvim-tree.actions.dir-up'.fn,
|
||||
first_sibling = require'nvim-tree.actions.movements'.sibling(-math.huge),
|
||||
full_rename = require'nvim-tree.actions.rename-file'.fn(true),
|
||||
last_sibling = require'nvim-tree.actions.movements'.sibling(math.huge),
|
||||
next_git_item = go_to('next_git_item'),
|
||||
next_sibling = require'nvim-tree.actions.movements'.sibling(1),
|
||||
parent_node = require'nvim-tree.actions.movements'.parent_node(false),
|
||||
paste = require'nvim-tree.actions.copy-paste'.paste,
|
||||
close_node = lib.close_node,
|
||||
parent_node = require'nvim-tree.actions.movements'.parent_node,
|
||||
toggle_ignored = lib.toggle_ignored,
|
||||
prev_git_item = go_to('prev_git_item'),
|
||||
prev_sibling = require'nvim-tree.actions.movements'.sibling(-1),
|
||||
refresh = require'nvim-tree.actions.reloaders'.reload_explorer,
|
||||
remove = require'nvim-tree.actions.remove-file'.fn,
|
||||
rename = require'nvim-tree.actions.rename-file'.fn(false),
|
||||
system_open = require'nvim-tree.actions.system-open'.fn,
|
||||
toggle_dotfiles = lib.toggle_dotfiles,
|
||||
toggle_help = lib.toggle_help,
|
||||
refresh = require'nvim-tree.actions.reloaders'.reload_explorer,
|
||||
first_sibling = require'nvim-tree.actions.movements'.sibling(-math.huge),
|
||||
last_sibling = require'nvim-tree.actions.movements'.sibling(math.huge),
|
||||
prev_sibling = require'nvim-tree.actions.movements'.sibling(-1),
|
||||
next_sibling = require'nvim-tree.actions.movements'.sibling(1),
|
||||
prev_git_item = go_to('prev_git_item'),
|
||||
next_git_item = go_to('next_git_item'),
|
||||
dir_up = require'nvim-tree.actions.dir-up'.fn,
|
||||
close = function() require'nvim-tree'.close() end,
|
||||
preview = function(node)
|
||||
if node.name == '..' then
|
||||
return
|
||||
end
|
||||
if node.nodes ~= nil then
|
||||
return lib.expand_or_collapse(node)
|
||||
end
|
||||
return require'nvim-tree.actions.open-file'.fn('preview', node.absolute_path)
|
||||
end,
|
||||
system_open = require'nvim-tree.actions.system-open'.fn,
|
||||
toggle_ignored = lib.toggle_ignored,
|
||||
trash = require'nvim-tree.actions.trash'.fn,
|
||||
}
|
||||
|
||||
@@ -105,7 +96,12 @@ function M.on_keypress(action)
|
||||
return default_function(node)
|
||||
end
|
||||
|
||||
if node.name == ".." then
|
||||
if action == "preview" then
|
||||
if node.name == '..' then return end
|
||||
if not node.nodes then
|
||||
return require'nvim-tree.actions.open-file'.fn('preview', node.absolute_path)
|
||||
end
|
||||
elseif node.name == ".." then
|
||||
return require'nvim-tree.actions.change-dir'.fn("..")
|
||||
elseif action == "cd" and node.nodes ~= nil then
|
||||
return require'nvim-tree.actions.change-dir'.fn(lib.get_last_group_node(node).absolute_path)
|
||||
|
||||
@@ -31,31 +31,33 @@ local function get_line_from_node(node, find_parent)
|
||||
end
|
||||
|
||||
|
||||
function M.parent_node(node, should_close)
|
||||
if node.name == '..' then return end
|
||||
function M.parent_node(should_close)
|
||||
return function(node)
|
||||
if node.name == '..' then return end
|
||||
|
||||
should_close = should_close or false
|
||||
local altered_tree = false
|
||||
should_close = should_close or false
|
||||
local altered_tree = false
|
||||
|
||||
local iter = get_line_from_node(node, true)
|
||||
if node.open == true and should_close then
|
||||
node.open = false
|
||||
altered_tree = true
|
||||
else
|
||||
local line, parent = iter(lib().Tree.nodes, true)
|
||||
if parent == nil then
|
||||
line = 1
|
||||
elseif should_close then
|
||||
parent.open = false
|
||||
local iter = get_line_from_node(node, true)
|
||||
if node.open == true and should_close then
|
||||
node.open = false
|
||||
altered_tree = true
|
||||
else
|
||||
local line, parent = iter(lib().Tree.nodes, true)
|
||||
if parent == nil then
|
||||
line = 1
|
||||
elseif should_close then
|
||||
parent.open = false
|
||||
altered_tree = true
|
||||
end
|
||||
line = view.View.hide_root_folder and line - 1 or line
|
||||
view.set_cursor({line, 0})
|
||||
end
|
||||
line = view.View.hide_root_folder and line - 1 or line
|
||||
view.set_cursor({line, 0})
|
||||
end
|
||||
|
||||
if altered_tree then
|
||||
diagnostics.update()
|
||||
lib().redraw()
|
||||
if altered_tree then
|
||||
diagnostics.update()
|
||||
lib().redraw()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user