Skip to content

vim: Fix dot repeat after macro replay not capturing insertion text#57684

Merged
smitbarmase merged 2 commits into
zed-industries:mainfrom
Fanteria:47251-repeat-does-not-repeat-macros
May 27, 2026
Merged

vim: Fix dot repeat after macro replay not capturing insertion text#57684
smitbarmase merged 2 commits into
zed-industries:mainfrom
Fanteria:47251-repeat-does-not-repeat-macros

Conversation

@Fanteria

@Fanteria Fanteria commented May 25, 2026

Copy link
Copy Markdown
Contributor

Closes #47251

Fix dot (.) repeat not correctly repeating the last change after replaying a macro (@register) (#47251)

When replaying a macro that contains text insertions, replay_insert_event calls handle_input directly and never emits InputHandled, so the observe_insertion subscription never fires. This left the dot register stale — . after @register would repeat an earlier change instead of the last one made by the macro.

Fix by calling observe_insertion explicitly in the ReplayableAction::Insertion branch of Replayer::next.

Release Notes:

  • Fixed dot (.) repeat not repeating the last change made by a macro (@register).

…ed-industries#47251)

Fix by calling `observe_insertion` explicitly in the `ReplayableAction::Insertion`
branch of `Replayer::next`.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label May 25, 2026
@smitbarmase smitbarmase added the area:parity/vim Feedback for Vim parity features label May 26, 2026

@smitbarmase smitbarmase left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but I don't think this is the right way to approach this. Consider this test:

cx.set_state("ˇfoo foo", Mode::Normal);
cx.simulate_keystrokes("q l c f o x escape q");
cx.assert_state("ˇxo foo", Mode::Normal);

cx.simulate_keystrokes("w @ l");
cx.assert_state("xo ˇxo", Mode::Normal);

cx.simulate_keystrokes(".");
cx.assert_state("xo xˇ", Mode::Normal);

With this PR, the final state becomes xo ox. The replay path treats the o from f o as inserted text, so when . runs it inserts an extra o.

@smitbarmase smitbarmase self-assigned this May 27, 2026
@zed-industries-bot

Copy link
Copy Markdown
Contributor
Messages
📖

This PR includes links to the following GitHub Issues: #47251
If this PR aims to close an issue, please include a Closes #ISSUE line at the top of the PR body.

Generated by 🚫 dangerJS against 2dfdf90

@smitbarmase smitbarmase left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I made a fix. Now replay_insert_event emits InputHandled when input is enabled, and the existing early return when input is disabled covers the Normal mode case, which I found was broken.

We already call observe_insertion from the InputHandled path here:

} => Vim::globals(cx).observe_insertion(text, range_to_replace.clone()),

@smitbarmase smitbarmase added this pull request to the merge queue May 27, 2026
Merged via the queue into zed-industries:main with commit 80a4042 May 27, 2026
33 checks passed
@Fanteria Fanteria deleted the 47251-repeat-does-not-repeat-macros branch May 27, 2026 21:06
@Fanteria

Copy link
Copy Markdown
Contributor Author

I'm sorry for missing that. Thanks for catching it and pushing the fix.

TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 2, 2026
…ed-industries#57684)

Closes zed-industries#47251

Fix dot (`.`) repeat not correctly repeating the last change after
replaying a macro (`@register`)
([zed-industries#47251](zed-industries#47251))

When replaying a macro that contains text insertions,
`replay_insert_event` calls `handle_input` directly and never emits
`InputHandled`, so the `observe_insertion` subscription never fires.
This left the dot register stale — `.` after `@register` would repeat an
earlier change instead of the last one made by the macro.

Fix by calling `observe_insertion` explicitly in the
`ReplayableAction::Insertion` branch of `Replayer::next`.

Release Notes:

- Fixed dot (`.`) repeat not repeating the last change made by a macro
(`@register`).

---------

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:parity/vim Feedback for Vim parity features cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vim mode: Repeat does not repeat macros

3 participants