Skip to content

Fix gb repeat count persisting across subsequent calls#9941

Closed
danielalanbates wants to merge 1 commit intoVSCodeVim:masterfrom
danielalanbates:fix/gb-repeat-count-4075
Closed

Fix gb repeat count persisting across subsequent calls#9941
danielalanbates wants to merge 1 commit intoVSCodeVim:masterfrom
danielalanbates:fix/gb-repeat-count-4075

Conversation

@danielalanbates
Copy link
Copy Markdown

Summary

Fixes #4075

When using gb with a count (e.g. 5gb), the count persists in the RecordedState for subsequent gb calls that don't specify a count. This causes 5gb gb to create 10 cursors instead of the expected 6.

Root cause: gb (ActionOverrideCmdD) has runsOnceForEachCountPrefix = true, which causes execCount to repeat exec based on vimState.recordedState.count. However, gb transitions into Visual mode, and RecordedState is only reset when returning to Normal mode (in modeHandler.ts line ~891). So the count from 5gb leaks into the next gb invocation.

Fix: Override execCount in ActionOverrideCmdD to reset recordedState.count to 0 after the parent execCount completes. This ensures the count is consumed by the command that specified it and defaults back to 1 for subsequent calls without an explicit count.

Test plan

  • 5gb on a word with 5+ occurrences should select 5 additional occurrences (6 total cursors) - unchanged behavior
  • After 5gb, pressing gb again (without a count) should add exactly 1 more cursor (7 total) - previously it added 5 more
  • 3gb gb gb should create 5 total cursors (1 original + 3 from count + 1 + 1) - previously created 10
  • gb without any count should still work as before (add 1 cursor per invocation)
  • <D-d> (Cmd+D on macOS) should continue to work identically to gb

This PR was created with the assistance of Claude Opus 4.6 by Anthropic. Happy to make any adjustments! Reviewed and submitted by a human.

)

When using `gb` with a count (e.g. `5gb`), the count was persisting in
the RecordedState for subsequent `gb` calls without a count. This caused
`5gb gb` to create 10 cursors instead of the expected 6, because the
RecordedState is only reset when returning to Normal mode, but `gb`
enters Visual mode.

Reset `recordedState.count` after `execCount` completes so the count is
consumed by the command that specified it and does not leak into
subsequent invocations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@danielalanbates
Copy link
Copy Markdown
Author

Thank you for your time reviewing this. We're withdrawing this PR. Apologies for any inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repeating gb once when selecting Multi-Cursors means subsequent gb are repeated that amount

1 participant