aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter.lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim/treesitter.lua')
-rw-r--r--runtime/lua/vim/treesitter.lua13
1 files changed, 10 insertions, 3 deletions
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua
index 96b1e24ba9..a15d3ec23c 100644
--- a/runtime/lua/vim/treesitter.lua
+++ b/runtime/lua/vim/treesitter.lua
@@ -411,6 +411,7 @@ function M.show_tree(opts)
vim.bo[b].buflisted = false
vim.bo[b].buftype = 'nofile'
vim.bo[b].bufhidden = 'wipe'
+ vim.bo[b].filetype = 'query'
local title = opts.title
if not title then
@@ -425,9 +426,6 @@ function M.show_tree(opts)
pg:draw(b)
- vim.fn.matchadd('Comment', '\\[[0-9:-]\\+\\]')
- vim.fn.matchadd('String', '".*"')
-
a.nvim_buf_clear_namespace(buf, pg.ns, 0, -1)
a.nvim_buf_set_keymap(b, 'n', '<CR>', '', {
desc = 'Jump to the node under the cursor in the source buffer',
@@ -467,6 +465,15 @@ function M.show_tree(opts)
end_col = math.max(0, pos.end_col),
hl_group = 'Visual',
})
+
+ local topline, botline = vim.fn.line('w0', win), vim.fn.line('w$', win)
+
+ -- Move the cursor if highlighted range is completely out of view
+ if pos.lnum < topline and pos.end_lnum < topline then
+ a.nvim_win_set_cursor(win, { pos.end_lnum + 1, 0 })
+ elseif pos.lnum > botline and pos.end_lnum > botline then
+ a.nvim_win_set_cursor(win, { pos.lnum + 1, 0 })
+ end
end,
})