Skip to content

Commit

Permalink
Fix: target line was not changed
Browse files Browse the repository at this point in the history
Lines aren't swappped if the origin line is longer than the target.  The
origin line is replaced by the target line, but the target line remains
unchanged.  The cause is passing 1-indexed number of line
`nvim_buf_get_offset`,  but the function accepts a 0-indexed line
number.
  • Loading branch information
ANtlord authored and gbprod committed Jul 8, 2022
1 parent 74c4e2d commit 683d3f9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lua/substitute/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ function utils.compare_regions(origin, target)
end

local origin_offset = {
start = vim.api.nvim_buf_get_offset(0, origin.marks.start.row) + origin.marks.start.col,
finish = vim.api.nvim_buf_get_offset(0, origin.marks.finish.row) + origin.marks.finish.col,
start = vim.api.nvim_buf_get_offset(0, origin.marks.start.row - 1) + origin.marks.start.col,
finish = vim.api.nvim_buf_get_offset(0, origin.marks.finish.row - 1) + origin.marks.finish.col,
}

local target_offset = {
start = vim.api.nvim_buf_get_offset(0, target.marks.start.row) + target.marks.start.col,
finish = vim.api.nvim_buf_get_offset(0, target.marks.finish.row) + target.marks.finish.col,
start = vim.api.nvim_buf_get_offset(0, target.marks.start.row - 1) + target.marks.start.col,
finish = vim.api.nvim_buf_get_offset(0, target.marks.finish.row - 1) + target.marks.finish.col,
}

-- < if origin comes before target
Expand Down

0 comments on commit 683d3f9

Please sign in to comment.