fix: update last cursor on first CursorMoved (#16698)

Closes https://github.com/neovim/neovim/issues/16625 https://github.com/neovim/neovim/issues/12923

The first defined CursorMoved autocommand will immediately
fire if the cursor has previously moved upon definition
of the autocommand.

Plugins add dummy autocommands such as:

```lua
autocmd CursorMoved * execute ''
```

to avoid this behavior.

Instead, when defining a new CursorHold autocommand, force
update the last cursor position.

See https://github.com/vim/vim/issues/2053
This commit is contained in:
Michael Lingelbach
2021-12-18 19:18:47 -08:00
committed by GitHub
parent 95803f0e90
commit b42e0c40c8
2 changed files with 14 additions and 0 deletions

View File

@@ -932,6 +932,12 @@ static int do_autocmd_event(event_T event, char_u *pat, bool once, int nested, c
last_mode = get_mode();
}
// If the event is CursorMoved, update the last cursor position
// position to avoid immediately triggering the autocommand
if (event == EVENT_CURSORMOVED && !has_event(EVENT_CURSORMOVED)) {
curwin->w_last_cursormoved = curwin->w_cursor;
}
ap->cmds = NULL;
*prev_ap = ap;
last_autopat[(int)event] = ap;