Skip to content

Fix zero-width regex replacements#808

Closed
lawrence3699 wants to merge 1 commit intomicrosoft:mainfrom
lawrence3699:codex/fix-zero-width-regex-replace
Closed

Fix zero-width regex replacements#808
lawrence3699 wants to merge 1 commit intomicrosoft:mainfrom
lawrence3699:codex/fix-zero-width-regex-replace

Conversation

@lawrence3699
Copy link
Copy Markdown

Fixes #775.

Replacing a zero-width regex match currently relies on having an active selection.
That works for normal matches, but patterns like $ produce an empty match, so the selection is cleared and both Replace and Replace All turn into no-ops.

This change keeps track of the active regex match separately from the visible selection so zero-width matches can still be replaced.
After replacing an empty match, Replace All now advances past the next grapheme (or forces a wrap at EOF) so it does not get stuck on the same logical position.
The cached zero-width match is also ignored once the cursor moves away, so Replace does not insert at a stale location.

Validation:

  • cargo fmt --all
  • cargo test -p edit

@lhecker
Copy link
Copy Markdown
Member

lhecker commented Apr 27, 2026

We've received two PRs about within a few days of each other. I believe #815 is unfortunately superior so I'll be closing this PR for now. That said, I'm not sure I'm happy with #815 either.

@lhecker lhecker closed this Apr 27, 2026
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.

Can't replace zero width regex matches with text

2 participants