From 5948aba886e8aad26043402684cf85c307813c4d Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 22 Aug 2020 20:46:40 +0200 Subject: feat(refactor.navigation): add navigation.goto_{next,previous}_usage --- lua/nvim-treesitter/ts_utils.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lua/nvim-treesitter/ts_utils.lua') diff --git a/lua/nvim-treesitter/ts_utils.lua b/lua/nvim-treesitter/ts_utils.lua index 52fdd0fc..6647cc96 100644 --- a/lua/nvim-treesitter/ts_utils.lua +++ b/lua/nvim-treesitter/ts_utils.lua @@ -276,4 +276,24 @@ function M.swap_nodes(node_or_range1, node_or_range2, bufnr, cursor_to_second) end end +function M.goto_node(node, goto_end, avoid_set_jump) + if not node then return end + if not avoid_set_jump then + utils.set_jump() + end + local range = {node:range()} + local position + if not goto_end then + position = { range[1], range[2] } + else + -- ranges are exclusive: -1 character! + if range[4] == 0 then + position = { range[3] - 1, -1 } + else + position = { range[3], range[4] - 1 } + end + end + api.nvim_win_set_cursor(0, { position[1] + 1, position[2] }) +end + return M -- cgit v1.2.3