mfussenegger/nvim-treehopper

Cursor position outside buffer

ram02z opened this issue · 1 comments

I have only tested the operator mode bind, which in my case I have set to m. The error occurs when the selected hint is on the first row and first column as demonstrated in the gif below.

ts-hint

Error:

E5108: Error executing lua ...ite/pack/packer/opt/nvim-ts-hint-textobject/lua/tsht.lua:73: 
Cursor position outside of buffer

Edit:
The issue occurs that when end_col equals 0 and/or end_row equals the amount of lines in the buffer. The following is my not so elegant way of solving this issue.

diff --git a/lua/tsht.lua b/lua/tsht.lua
index a3540f9..45272d6 100644
--- a/lua/tsht.lua
+++ b/lua/tsht.lua
@@ -70,7 +70,14 @@ function M.nodes()
         local start_row, start_col, end_row, end_col = node:range()
         api.nvim_win_set_cursor(0, { start_row + 1, start_col })
         vim.cmd('normal! v')
-        api.nvim_win_set_cursor(0, { end_row + 1, end_col - 1 })
+        local line_count = api.nvim_buf_line_count(0)
+        if end_row < line_count then
+          end_row = end_row + 1
+        end
+        if end_col > 0 then
+          end_col = end_col - 1
+        end
+        api.nvim_win_set_cursor(0, { end_row, end_col })
         api.nvim_buf_clear_namespace(0, ns, 0, -1)
         break
       else

Thank you for reporting, should be fixed with 3bae940