vim-patch:9.0.2075: TextChangedI may not always trigger (#25808)

Problem:  TextChangedI may not always trigger
Solution: trigger it in more cases: for insert/
          append/change operations, and when
          opening a new line,

fixes: vim/vim#13367
closes: vim/vim#13375

4bca4897a1

Co-authored-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2023-10-28 10:42:18 +08:00
committed by GitHub
parent f97248db75
commit ac353e87ae
5 changed files with 75 additions and 26 deletions

View File

@@ -143,9 +143,6 @@ static void insert_enter(InsertState *s)
update_Insstart_orig = true;
ins_compl_clear(); // clear stuff for CTRL-X mode
// Reset Changedtick_i, so that TextChangedI will only be triggered for stuff
// from insert mode
curbuf->b_last_changedtick_i = buf_get_changedtick(curbuf);
// Trigger InsertEnter autocommands. Do not do this for "r<CR>" or "grx".
if (s->cmdchar != 'r' && s->cmdchar != 'v') {

View File

@@ -5724,6 +5724,8 @@ static void n_opencmd(cmdarg_T *cap)
(void)hasFolding(curwin->w_cursor.lnum,
NULL, &curwin->w_cursor.lnum);
}
// trigger TextChangedI for the 'o/O' command
curbuf->b_last_changedtick_i = buf_get_changedtick(curbuf);
if (u_save(curwin->w_cursor.lnum - (cap->cmdchar == 'O' ? 1 : 0),
curwin->w_cursor.lnum + (cap->cmdchar == 'o' ? 1 : 0))
&& open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD,
@@ -6265,6 +6267,11 @@ static void invoke_edit(cmdarg_T *cap, int repl, int cmd, int startln)
// Always reset "restart_edit", this is not a restarted edit.
restart_edit = 0;
// Reset Changedtick_i, so that TextChangedI will only be triggered for stuff
// from insert mode, for 'o/O' this has already been done in n_opencmd
if (cap->cmdchar != 'O' && cap->cmdchar != 'o') {
curbuf->b_last_changedtick_i = buf_get_changedtick(curbuf);
}
if (edit(cmd, startln, cap->count1)) {
cap->retval |= CA_COMMAND_BUSY;
}

View File

@@ -6226,6 +6226,9 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
// Restore linebreak, so that when the user edits it looks as before.
restore_lbr(lbr_saved);
// trigger TextChangedI
curbuf->b_last_changedtick_i = buf_get_changedtick(curbuf);
if (op_change(oap)) { // will call edit()
cap->retval |= CA_COMMAND_BUSY;
}
@@ -6324,6 +6327,9 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
// Restore linebreak, so that when the user edits it looks as before.
restore_lbr(lbr_saved);
// trigger TextChangedI
curbuf->b_last_changedtick_i = buf_get_changedtick(curbuf);
op_insert(oap, cap->count1);
// Reset linebreak, so that formatting works correctly.