Skip to content

Commit 6e885e4

Browse files
committed
fix(ai): make empty textobject work with selection=exclusive
Resolve #2124
1 parent b409fd1 commit 6e885e4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lua/mini/ai.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ MiniAi.select_textobject = function(ai_type, id, opts)
11251125
vim.cmd('normal! zv')
11261126
vim.cmd('normal! ' .. vis_mode)
11271127
set_cursor(tobj.to)
1128-
if vim.o.selection == 'exclusive' then vim.cmd('set whichwrap=l | normal! l') end
1128+
if vim.o.selection == 'exclusive' and not tobj_is_empty then vim.cmd('set whichwrap=l | normal! l') end
11291129
vim.cmd('normal! zv')
11301130

11311131
-- Restore horizontal view which was possibly affected by moving cursor

tests/test_ai.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,9 @@ T['select_textobject()']["respects 'selection=exclusive'"] = function()
10441044

10451045
validate('i', ' () ')
10461046
validate('a', ' ')
1047+
1048+
-- Works with empty regions
1049+
validate_select1d(' () ', 0, { 'i', ')' }, { 3, 3 })
10471050
end
10481051

10491052
T['select_textobject()']['respects `vis_mode` from textobject region'] = function()
@@ -1783,6 +1786,10 @@ T['Textobject']['works with empty output region'] = function()
17831786

17841787
validate(0)
17851788
validate(1)
1789+
1790+
child.o.selection = 'exclusive'
1791+
validate(0)
1792+
validate(1)
17861793
end
17871794

17881795
T['Textobject']['handles horizontal view for out of view textobjects'] = function()

0 commit comments

Comments
 (0)