Skip to content

Commit

Permalink
fix: column indexing (#572)
Browse files Browse the repository at this point in the history
We started in 75d3de9, this should finish the job by restoring correct behavior for "single_line" selection type.
  • Loading branch information
raffaem authored Apr 22, 2024
1 parent dca1c80 commit 9e65d60
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lua/toggleterm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 9e65d60

Please sign in to comment.