Skip to content

Commit

Permalink
fix: bounds check when restoring cursor position (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
mawkler committed Jan 17, 2025
1 parent 9f0cb49 commit b491aaa
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lua/nvim-surround/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ M.set_curpos = function(pos)
if not pos then
return
end
vim.api.nvim_win_set_cursor(0, { pos[1], pos[2] - 1 })

local line = math.min(pos[1], vim.api.nvim_buf_line_count(0))
local column = pos[2] - 1

vim.api.nvim_win_set_cursor(0, { line, column })
end

-- Move the cursor to a location in the buffer, depending on the `move_cursor` setting.
Expand Down

0 comments on commit b491aaa

Please sign in to comment.