aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Groß <magnus.gross@rwth-aachen.de>2021-10-23 20:55:52 +0200
committerMagnus Groß <magnus.gross@rwth-aachen.de>2021-11-18 11:23:18 +0100
commitfdfd1eda434b70b02b4cb804546c97ef8ff09049 (patch)
tree39fcf590ffa0543f0ad2de53562653887eeb9374
parent11683193f597e1b3144ba65f08056cd44b19175f (diff)
downloadrneovim-fdfd1eda434b70b02b4cb804546c97ef8ff09049.tar.gz
rneovim-fdfd1eda434b70b02b4cb804546c97ef8ff09049.tar.bz2
rneovim-fdfd1eda434b70b02b4cb804546c97ef8ff09049.zip
feat: trigger ModeChanged for terminal modes
-rw-r--r--src/nvim/terminal.c1
-rw-r--r--test/functional/autocmd/modechanged_spec.lua31
2 files changed, 32 insertions, 0 deletions
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index 35c68fa1f6..30f6ae6f34 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -412,6 +412,7 @@ void terminal_enter(void)
curwin->w_redr_status = true; // For mode() in statusline. #8323
ui_busy_start();
apply_autocmds(EVENT_TERMENTER, NULL, NULL, false, curbuf);
+ trigger_modechanged();
s->state.execute = terminal_execute;
s->state.check = terminal_check;
diff --git a/test/functional/autocmd/modechanged_spec.lua b/test/functional/autocmd/modechanged_spec.lua
new file mode 100644
index 0000000000..be5a291ac9
--- /dev/null
+++ b/test/functional/autocmd/modechanged_spec.lua
@@ -0,0 +1,31 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq
+local feed, command = helpers.feed, helpers.command
+
+describe('ModeChanged', function()
+ before_each(function()
+ clear()
+ command('let g:count = 0')
+ command('au ModeChanged * let g:event = copy(v:event)')
+ command('au ModeChanged * let g:count += 1')
+ end)
+
+ it('picks up terminal mode changes', function()
+ command("term")
+ feed('i')
+ eq({
+ old_mode = 'nt',
+ new_mode = 't'
+ }, eval('g:event'))
+ feed('<c-\\><c-n>')
+ eq({
+ old_mode = 't',
+ new_mode = 'nt'
+ }, eval('g:event'))
+ eq(3, eval('g:count'))
+ command("bd!")
+
+ -- v:event is cleared after the autocommand is done
+ eq({}, eval('v:event'))
+ end)
+end)