From bf4b80551660e978a2024af602851d5b51cb3f4b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 16 Jan 2024 10:42:09 +0800 Subject: [PATCH] fix(edit): don't go to Terminal mode when stopping Insert mode (#27033) --- src/nvim/edit.c | 2 +- test/functional/terminal/ex_terminal_spec.lua | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 80acabc51d..0cc84966ec 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -393,7 +393,7 @@ static int insert_check(VimState *state) Insstart_orig = Insstart; } - if (curbuf->terminal) { + if (curbuf->terminal && !stop_insert_mode) { // Exit Insert mode and go to Terminal mode. stop_insert_mode = true; restart_edit = 'I'; diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 427146b2e5..93945b0365 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -139,6 +139,15 @@ describe(':terminal', function() eq({ blocking=false, mode='t' }, nvim('get_mode')) eq({'InsertLeave', 'TermEnter'}, eval('g:events')) end) + + it('switching to terminal buffer immediately after :stopinsert #27031', function() + command('terminal') + command('vnew') + feed('i') + eq({ blocking = false, mode = 'i' }, nvim('get_mode')) + command('stopinsert | wincmd p') + eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) + end) end) local function test_terminal_with_fake_shell(backslash)