feat(#1245): add next_diag_item and prev_diag_item actions

This commit is contained in:
Alexander Courtis
2022-07-03 16:04:49 +10:00
parent 21516f447b
commit 80d4f28383
5 changed files with 41 additions and 7 deletions

View File

@@ -153,11 +153,21 @@ local DEFAULT_MAPPINGS = {
action = "copy_absolute_path",
desc = "copy absolute path to system clipboard",
},
{
key = "[e",
action = "prev_diag_item",
desc = "go to next diagnostic item",
},
{
key = "[c",
action = "prev_git_item",
desc = "go to next git item",
},
{
key = "]e",
action = "next_diag_item",
desc = "go to prev diagnostic item",
},
{
key = "]c",
action = "next_git_item",
@@ -243,11 +253,13 @@ local keypress_funcs = {
last_sibling = require("nvim-tree.actions.movements").sibling(math.huge),
live_filter = require("nvim-tree.live-filter").start_filtering,
clear_live_filter = require("nvim-tree.live-filter").clear_filter,
next_git_item = require("nvim-tree.actions.movements").find_git_item "next",
next_diag_item = require("nvim-tree.actions.movements").find_item("next", "diag"),
next_git_item = require("nvim-tree.actions.movements").find_item("next", "git"),
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,
prev_git_item = require("nvim-tree.actions.movements").find_git_item "prev",
prev_diag_item = require("nvim-tree.actions.movements").find_item("prev", "diag"),
prev_git_item = require("nvim-tree.actions.movements").find_item("prev", "git"),
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,

View File

@@ -84,20 +84,27 @@ function M.sibling(direction)
end
end
function M.find_git_item(where)
function M.find_item(where, what)
return function()
local node_cur = lib.get_node_at_cursor()
local nodes_by_line = utils.get_nodes_by_line(core.get_explorer().nodes, core.get_nodes_starting_line())
local cur, first, prev, nex = nil, nil, nil, nil
for line, node in pairs(nodes_by_line) do
if not first and node.git_status then
local valid = false
if what == "git" then
valid = node.git_status ~= nil
elseif what == "diag" then
valid = node.diag_status ~= nil
end
if not first and valid then
first = line
end
if node == node_cur then
cur = line
elseif node.git_status then
elseif valid then
if not cur then
prev = line
end