range: add extmark utilities
All checks were successful
NeoVim tests / code-quality (push) Successful in 1m22s

This commit is contained in:
2025-06-11 20:04:46 -06:00
parent 6f86bfaa42
commit 859187585b
3 changed files with 88 additions and 0 deletions

View File

@@ -617,4 +617,29 @@ describe('Range', function()
}, vim.api.nvim_buf_get_lines(b, 0, -1, false))
end)
end)
it('can save to extmark', function()
withbuf({
'The quick brown',
'fox',
'jumps',
'over',
'the lazy dog',
}, function()
-- Construct a range over 'fox jumps'
local r = Range.new(Pos.new(nil, 2, 1), Pos.new(nil, 3, Pos.MAX_COL), 'V')
local extrange = r:save_to_extmark()
assert.are.same({ 'fox', 'jumps' }, extrange:range():lines())
-- change 'jumps' to 'leaps':
vim.api.nvim_buf_set_text(extrange.bufnr, 2, 0, 2, 4, { 'leap' })
assert.are.same({
'The quick brown',
'fox',
'leaps',
'over',
'the lazy dog',
}, vim.api.nvim_buf_get_lines(extrange.bufnr, 0, -1, false))
assert.are.same({ 'fox', 'leaps' }, extrange:range():lines())
end)
end)
end)