@@ -202,10 +202,26 @@ local function highlight_node(node)
202
202
end
203
203
204
204
local range = module .required [" core.integrations.treesitter" ].get_node_range (node )
205
+ if range .column_end == 0 then
206
+ range .row_end = range .row_end - 1
207
+ range .column_end = vim .api .nvim_buf_get_lines (0 , range .row_end , range .row_end + 1 , true )[1 ]:len ()
208
+ end
209
+ if range .column_start == vim .api .nvim_buf_get_lines (0 , range .row_start , range .row_start + 1 , true )[1 ]:len () then
210
+ range .row_start = range .row_start + 1
211
+ range .column_start = 0
212
+ end
213
+
214
+ -- This method of selection is from ts_utils, it avoids a bug with the nvim_buf_set_mark
215
+ -- approach
216
+ local selection_mode = " v"
217
+ local mode = vim .api .nvim_get_mode ()
218
+ if mode .mode ~= selection_mode then
219
+ vim .cmd .normal ({ selection_mode , bang = true })
220
+ end
205
221
206
- vim .api .nvim_buf_set_mark (0 , " < " , range .row_start + 1 , range .column_start , { })
207
- vim .api . nvim_buf_set_mark ( 0 , " > " , range . row_end + 1 , range . column_end , { })
208
- vim .cmd ( " normal! gv " )
222
+ vim .api .nvim_win_set_cursor (0 , { range .row_start + 1 , range .column_start })
223
+ vim .cmd . normal ({ bang = true , args = { " o " } })
224
+ vim .api . nvim_win_set_cursor ( 0 , { range . row_end + 1 , range . column_end } )
209
225
end
210
226
211
227
module .config .private = {
0 commit comments