more cleanup
All checks were successful
NeoVim tests / plenary-tests (push) Successful in 10s

This commit is contained in:
2025-04-13 21:49:48 -06:00
parent 58e447aad6
commit 466698a9de
3 changed files with 10 additions and 22 deletions

View File

@@ -170,29 +170,19 @@ function M.setup()
local irange = Range.from_motion('i' .. from_c, { user_defined = true })
if arange == nil or irange == nil then return end
local lrange = Range.new(arange.start, irange.start:must_next(-1))
local rrange = Range.new(irange.stop:must_next(1), arange.stop)
local lrange, rrange = arange:difference(irange)
if not lrange or not rrange then return end
rrange:replace(to.right)
lrange:replace(to.left)
else
-- replace `from.right` with `to.right`:
local last_line = arange:line(-1):text()
local from_right_match = last_line:match(vim.pesc(from.right) .. '$')
if from_right_match then
local match_start = arange.stop:clone()
match_start.col = match_start.col - #from_right_match + 1
Range.new(match_start, arange.stop):replace(to.right)
end
local right_text = arange:sub(-1, -#from.right)
right_text:replace(to.right)
-- replace `from.left` with `to.left`:
local first_line = arange:line(1):text()
local from_left_match = first_line:match('^' .. vim.pesc(from.left))
if from_left_match then
local match_end = arange.start:clone()
match_end.col = match_end.col + #from_left_match - 1
Range.new(arange.start, match_end):replace(to.left)
end
local left_text = arange:sub(1, #from.left)
left_text:replace(to.left)
end
end)
end, { noremap = true, silent = true })