fix: column indexing (#572)

We started in 75d3de9d26, this should finish the job by restoring correct behavior for "single_line" selection type.
This commit is contained in:
Raffaele Mancuso 2024-04-22 08:59:25 +02:00 committed by GitHub
parent dca1c80fb8
commit 9e65d60cfa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -220,12 +220,16 @@ function M.send_lines_to_terminal(selection_type, trim_spaces, cmd_data)
local start_line, start_col
if selection_type == "single_line" then
start_line, start_col = unpack(api.nvim_win_get_cursor(0))
-- nvim_win_get_cursor uses 0-based indexing for columns, while we use 1-based indexing
start_col = start_col + 1
table.insert(lines, fn.getline(start_line))
else
local res = nil
if string.match(selection_type, "visual") then
-- This calls vim.fn.getpos, while uses 1-based indexing for columns
res = utils.get_line_selection("visual")
else
-- This calls vim.fn.getpos, while uses 1-based indexing for columns
res = utils.get_line_selection("motion")
end
start_line, start_col = unpack(res.start_pos)
@ -250,6 +254,7 @@ function M.send_lines_to_terminal(selection_type, trim_spaces, cmd_data)
-- Jump back with the cursor where we were at the beginning of the selection
api.nvim_set_current_win(current_window)
-- nvim_win_set_cursor() uses 0-based indexing for columns, while we use 1-based indexing
api.nvim_win_set_cursor(current_window, { start_line, start_col - 1 })
end