Skip to content

Commit 1ad462d

Browse files
committed
(mini.ai) Update <Esc> to cancel from Operator-pending to Normal mode.
Details: - Resolves #697.
1 parent 4f69339 commit 1ad462d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lua/mini/ai.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ end
11831183
H.expr_textobject = function(mode, ai_type, opts)
11841184
local tobj_id = H.user_textobject_id(ai_type)
11851185

1186-
if tobj_id == nil then return '' end
1186+
if tobj_id == nil then return mode == 'o' and '<Esc>' or '' end
11871187

11881188
-- Possibly fall back to builtin `a`/`i` textobjects
11891189
if H.is_disabled() or not H.is_valid_textobject_id(tobj_id) then

tests/test_ai.lua

+22
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,28 @@ T['Textobject']['works in Operator-pending mode'] = function()
14131413
validate_edit(lines, cursor, { 'aabb', 'ccc', 'ddee' }, { 1, 2 }, 'd<C-v>a)')
14141414
end
14151415

1416+
T['Textobject']['can be cancelled'] = function()
1417+
local validate = function(keys, mode)
1418+
set_lines({ 'aaa' })
1419+
set_cursor(1, 1)
1420+
type_keys(keys, '<Esc>')
1421+
1422+
eq(child.api.nvim_get_mode().mode, mode)
1423+
type_keys('<Esc>')
1424+
1425+
eq(get_lines(), { 'aaa' })
1426+
eq(get_cursor(), { 1, 1 })
1427+
1428+
child.ensure_normal_mode()
1429+
end
1430+
1431+
-- Visual mode should be cancelled without leaving Visual mode
1432+
validate({ 'v', 'i' }, 'v')
1433+
1434+
-- Operator-pending mode should be cancelled into Normal mode
1435+
validate({ 'd', 'i' }, 'n')
1436+
end
1437+
14161438
T['Textobject']['works with different mappings'] = function()
14171439
reload_module({ mappings = { around = 'A', inside = 'I' } })
14181440

0 commit comments

Comments
 (0)