support repeated Range:replace calls/empty ranges

- Range:replace now updates its bounds to reflect the replacement
- Support the notion of an empty range
This commit is contained in:
2024-11-12 07:48:23 -07:00
parent 58c1eca4da
commit 5c244cfc0a
3 changed files with 177 additions and 33 deletions

View File

@@ -49,6 +49,7 @@ function M.define_text_object(key_seq, fn, opts)
local function handle_visual()
local range_or_pos = fn(key_seq)
if range_or_pos == nil then return end
if Range.is(range_or_pos) and range_or_pos:is_empty() then range_or_pos = range_or_pos.start end
if Range.is(range_or_pos) then
local range = range_or_pos --[[@as Range]]
@@ -67,6 +68,7 @@ function M.define_text_object(key_seq, fn, opts)
local range_or_pos = fn(key_seq)
if range_or_pos == nil then return end
if Range.is(range_or_pos) and range_or_pos:is_empty() then range_or_pos = range_or_pos.start end
if Range.is(range_or_pos) then
range_or_pos:set_visual_selection()