Skip to content

Commit c72f6e6

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

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-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

+23
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,29 @@ T['Textobject']['works in Operator-pending mode'] = function()
14111411
validate_edit(lines, cursor, { 'aaee' }, { 1, 2 }, 'dva)')
14121412
validate_edit(lines, cursor, { '' }, { 1, 0 }, 'dVa)')
14131413
validate_edit(lines, cursor, { 'aabb', 'ccc', 'ddee' }, { 1, 2 }, 'd<C-v>a)')
1414+
1415+
end
1416+
1417+
T['Textobject']['can be cancelled'] = function()
1418+
local validate = function(keys, mode)
1419+
set_lines({ 'aaa' })
1420+
set_cursor(1, 1)
1421+
type_keys(keys, '<Esc>')
1422+
1423+
eq(child.api.nvim_get_mode().mode, mode)
1424+
type_keys('<Esc>')
1425+
1426+
eq(get_lines(), { 'aaa' })
1427+
eq(get_cursor(), { 1, 1 })
1428+
1429+
child.ensure_normal_mode()
1430+
end
1431+
1432+
-- Visual mode should be cancelled without leaving Visual mode
1433+
validate({ 'v', 'i' }, 'v')
1434+
1435+
-- Operator-pending mode should be cancelled into Normal mode
1436+
validate({ 'd', 'i' }, 'n')
14141437
end
14151438

14161439
T['Textobject']['works with different mappings'] = function()

0 commit comments

Comments
 (0)