Add mappings for jumping to previous or next git item.

This commit is contained in:
Kristijan Husak
2020-07-22 11:50:18 +02:00
parent 7743d90504
commit f1b04965de
5 changed files with 50 additions and 12 deletions

View File

@@ -58,6 +58,8 @@ function M.get_bindings()
cut = keybindings.cut or 'x',
copy = keybindings.copy or 'c',
paste = keybindings.paste or 'p',
prev_git_item = keybindings.prev_git_item or '[c',
next_git_item = keybindings.next_git_item or ']c',
}
end

View File

@@ -213,6 +213,8 @@ local function set_mappings()
[bindings.cut] = 'on_keypress("cut")';
[bindings.copy] = 'on_keypress("copy")';
[bindings.paste] = 'on_keypress("paste")';
[bindings.prev_git_item] = 'on_keypress("prev_git_item")';
[bindings.next_git_item] = 'on_keypress("next_git_item")';
gx = "xdg_open()";
}

View File

@@ -1,5 +1,6 @@
local luv = vim.loop
local lib = require'lib.lib'
local config = require'lib.config'
local colors = require'lib.colors'
local renderer = require'lib.renderer'
local fs = require'lib.fs'
@@ -28,6 +29,21 @@ function M.open()
end
end
local function go_to_git_item(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)
end
function M.on_keypress(mode)
local node = lib.get_node_at_cursor()
if not node then return end
@@ -55,6 +71,10 @@ 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)
end
if node.name == ".." then
return lib.change_dir("..")
elseif mode == "cd" and node.entries ~= nil then