aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter.lua
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-03-03 14:19:09 +0100
committerGitHub <noreply@github.com>2023-03-03 14:19:09 +0100
commit74c9c413e7600c96c1ad35b0433fc63563130eef (patch)
treef63bbdd42787f6288190a0a24647420adfc6fa25 /runtime/lua/vim/treesitter.lua
parentfbaf5bde55d42869ed6d9e9fc072110ac9976c66 (diff)
parent86ff239240e955ef6da95bc9c8814cfd4492f5aa (diff)
downloadrneovim-74c9c413e7600c96c1ad35b0433fc63563130eef.tar.gz
rneovim-74c9c413e7600c96c1ad35b0433fc63563130eef.tar.bz2
rneovim-74c9c413e7600c96c1ad35b0433fc63563130eef.zip
Merge pull request #22484 from gpanders/inspect-tree-fix-cursor
fix(treesitter): maintain cursor position when toggling anonymous nodes
Diffstat (limited to 'runtime/lua/vim/treesitter.lua')
-rw-r--r--runtime/lua/vim/treesitter.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua
index f80da433b1..b63247aa2c 100644
--- a/runtime/lua/vim/treesitter.lua
+++ b/runtime/lua/vim/treesitter.lua
@@ -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', '', {