Skip to content

Commit

Permalink
fix(bounds): edge-cases
Browse files Browse the repository at this point in the history
NStefan002 committed Jan 22, 2025
1 parent d5acf99 commit 73a3a21
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lua/visual-surround/init.lua
Original file line number Diff line number Diff line change
@@ -157,6 +157,8 @@ local function remove_surr(bounds, mode, opening, closing)
api.nvim_buf_set_lines(0, bounds.vline_start - 1, bounds.vline_end, true, lines)
end

new_bounds.vcol_start = math.max(0, new_bounds.vcol_start)
new_bounds.vcol_end = math.max(0, new_bounds.vcol_end)
util.update_visual_selection(new_bounds, mode)
end

6 changes: 3 additions & 3 deletions lua/visual-surround/util.lua
Original file line number Diff line number Diff line change
@@ -55,15 +55,15 @@ function M.get_bounds(mode)
vcol_start, vcol_end = vcol_end, vcol_start
end
end

-- fix the order of the columns if the user selects from bottom right to top left in viusal block mode
if mode == api.nvim_replace_termcodes("<c-v>", true, false, true) and vcol_start > vcol_end then
vcol_start, vcol_end = vcol_end, vcol_start
end

-- ajust the end column if the cursor is one character after the end of the line (visual mode enables this)
if vcol_end == vim.fn.col("$") then
vcol_end = vcol_end - 1
end
local last_line = vim.fn.getline(vline_end)
vcol_end = math.min(vcol_end, api.nvim_strwidth(last_line))

return {
vline_start = vline_start,

0 comments on commit 73a3a21

Please sign in to comment.