Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion lua/nvim-treesitter-textobjects/move.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ local function goto_node(range, goto_end, avoid_set_jump)
vim.cmd('normal! v')
end

-- end positions with `col=0` mean "up to the end of the previous line, including the newline character"
if end_col == 0 then
end_row = end_row - 1
end_col = #api.nvim_buf_get_lines(0, end_row, end_row + 1, true)[1]
else
end_col = end_col - 1
end

-- Position is 1, 0 indexed.
if not goto_end then
api.nvim_win_set_cursor(0, { start_row + 1, start_col })
else
api.nvim_win_set_cursor(0, { end_row + 1, end_col - 1 })
api.nvim_win_set_cursor(0, { end_row + 1, end_col })
end
end

Expand Down
11 changes: 9 additions & 2 deletions lua/nvim-treesitter-textobjects/select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@ local function update_selection(range, selection_mode)
vim.cmd.normal({ selection_mode, bang = true })
end

local end_col_offset = 1
-- end positions with `col=0` mean "up to the end of the previous line, including the newline character"
if end_col == 0 then
end_row = end_row - 1
-- +1 is needed because we are interpreting `end_col` to be exclusive afterwards
end_col = #api.nvim_buf_get_lines(0, end_row, end_row + 1, true)[1] + 1
end

local end_col_offset = 1
if selection_mode == 'v' and vim.o.selection == 'exclusive' then
end_col_offset = 0
end
end_col = end_col - end_col_offset

-- Position is 1, 0 indexed.
api.nvim_win_set_cursor(0, { start_row + 1, start_col })
vim.cmd('normal! o')
api.nvim_win_set_cursor(0, { end_row + 1, end_col - end_col_offset })
api.nvim_win_set_cursor(0, { end_row + 1, end_col })
end

local M = {}
Expand Down