Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix column indexing #572

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading