Cache functions for jumping to prev/next git item.
This commit is contained in:
parent
f1b04965de
commit
28c300acb4
27
lua/tree.lua
27
lua/tree.lua
@ -29,21 +29,18 @@ function M.open()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function go_to_git_item(mode)
|
||||
local function gen_go_to(mode)
|
||||
local icon_state = config.get_icon_state()
|
||||
if not icon_state.show_git_icon then return end
|
||||
|
||||
local icons = {}
|
||||
for _, icon in pairs(icon_state.icons.git_icons) do
|
||||
table.insert(icons, icon)
|
||||
end
|
||||
|
||||
icons = table.concat(icons, '\\|')
|
||||
local flags = mode == 'prev_git_item' and 'b' or ''
|
||||
return vim.fn.search(icons, flags)
|
||||
local icons = table.concat(vim.tbl_values(icon_state.icons.git_icons), '\\|')
|
||||
return function()
|
||||
return icon_state.show_git_icon and vim.fn.search(icons, flags)
|
||||
end
|
||||
end
|
||||
|
||||
local go_to_prev_git_item = gen_go_to('prev_git_item')
|
||||
local go_to_next_git_item = gen_go_to('next_git_item')
|
||||
|
||||
function M.on_keypress(mode)
|
||||
local node = lib.get_node_at_cursor()
|
||||
if not node then return end
|
||||
@ -71,8 +68,12 @@ function M.on_keypress(mode)
|
||||
return lib.toggle_ignored()
|
||||
end
|
||||
|
||||
if mode == 'next_git_item' or mode == 'prev_git_item' then
|
||||
return go_to_git_item(mode)
|
||||
if mode == 'prev_git_item' then
|
||||
return go_to_prev_git_item()
|
||||
end
|
||||
|
||||
if mode == 'next_git_item' then
|
||||
return go_to_next_git_item()
|
||||
end
|
||||
|
||||
if node.name == ".." then
|
||||
|
||||
Loading…
Reference in New Issue
Block a user