diff options
-rw-r--r-- | runtime/doc/autocmd.txt | 4 | ||||
-rw-r--r-- | src/nvim/auevents.lua | 1 | ||||
-rw-r--r-- | src/nvim/terminal.c | 12 | ||||
-rw-r--r-- | test/functional/terminal/buffer_spec.lua | 8 |
4 files changed, 25 insertions, 0 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index da41c92df6..c30c190301 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -996,6 +996,10 @@ TextChangedP After a change was made to the text in the current buffer in Insert mode, only when the popup menu is visible. Otherwise the same as TextChanged. + *TextChangedT* +TextChangedT After a change was made to the text in the + current buffer in |Terminal-mode|. Otherwise + the same as TextChanged. *TextYankPost* TextYankPost Just after a |yank| or |deleting| command, but not if the black hole register |quote_| is used nor diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua index 93a870fe04..65c22c922a 100644 --- a/src/nvim/auevents.lua +++ b/src/nvim/auevents.lua @@ -108,6 +108,7 @@ return { 'TextChanged', -- text was modified 'TextChangedI', -- text was modified in Insert mode(no popup) 'TextChangedP', -- text was modified in Insert mode(popup) + 'TextChangedT', -- text was modified in Terminal mode 'TextYankPost', -- after a yank or delete was done (y, d, c) 'UIEnter', -- after UI attaches 'UILeave', -- after UI detaches diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 5e221e13df..890b04a614 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -523,6 +523,18 @@ static int terminal_check(VimState *state) if (must_redraw) { update_screen(); + + // Make sure an invoked autocmd doesn't delete the buffer (and the + // terminal) under our fingers. + curbuf->b_locked++; + + // save and restore curwin and curbuf, in case the autocmd changes them + aco_save_T aco; + aucmd_prepbuf(&aco, curbuf); + apply_autocmds(EVENT_TEXTCHANGEDT, NULL, NULL, false, curbuf); + aucmd_restbuf(&aco); + + curbuf->b_locked--; } if (need_maketitle) { // Update title in terminal-mode. #7248 diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 9d10f43ec6..46d08897e0 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -410,6 +410,14 @@ describe('on_lines does not emit out-of-bounds line indexes when', function() feed_command('bdelete!') eq('', exec_lua([[return _G.cb_error]])) end) + + it('runs TextChangedT event', function() + meths.set_var('called', 0) + command('autocmd TextChangedT * ++once let g:called = 1') + feed_command('terminal') + feed('iaa') + eq(1, meths.get_var('called')) + end) end) it('terminal truncates number of composing characters to 5', function() |