Merge pull request #22484 from gpanders/inspect-tree-fix-cursor

fix(treesitter): maintain cursor position when toggling anonymous nodes
This commit is contained in:
Christian Clason
2023-03-03 14:19:09 +01:00
committed by GitHub
2 changed files with 22 additions and 3 deletions

View File

@@ -507,8 +507,26 @@ function M.inspect_tree(opts)
a.nvim_buf_set_keymap(b, 'n', 'a', '', {
desc = 'Toggle anonymous nodes',
callback = function()
local row, col = unpack(a.nvim_win_get_cursor(w))
local curnode = pg:get(row)
while curnode and not curnode.named do
row = row - 1
curnode = pg:get(row)
end
pg.opts.anon = not pg.opts.anon
pg:draw(b)
if not curnode then
return
end
local id = curnode.id
for i, node in pg:iter() do
if node.id == id then
a.nvim_win_set_cursor(w, { i, col })
end
end
end,
})
a.nvim_buf_set_keymap(b, 'n', 'I', '', {