Vim mode: double-Esc undo leaves normal mode, so '.' duplicates content on the very first keystroke
Description
In vim mode, using double-Esc to undo a message leaves the input in normal mode instead of insert mode. If the next keystroke is . (repeat last change), it duplicates the content — even though no edit has actually been made since the undo.
/rewind avoids that specific issue because it automatically enters insert mode after rewinding. However, if you then press Esc to go from insert mode back to normal mode, . still duplicates the content — so the underlying problem is broader than just double-Esc: a stale "last change" survives both undo paths and gets replayed by . even when no edit happened since.
Steps to reproduce
Case 1 (double-Esc undo):
- Enable vim mode.
- Type a message.
- Press Esc twice to undo the message.
- Press
.as the very first keystroke after the undo.
Case 2 (/rewind then Esc):
- Enable vim mode.
- Type a message.
- Run
/rewind. - Press Esc to go from insert mode to normal mode.
- Press
.as the first keystroke since.
Expected behavior
In both cases, . right after an undo/rewind (with no intervening edit) should be a no-op, since there's no new "last change" to repeat.
Actual behavior
In both cases, . duplicates content — it's replaying a change from before the undo/rewind rather than being a no-op.