[diff/editor] Add Find-in-file replace support#817
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 48bbf0da53
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| true, | ||
| this.#selections | ||
| ); |
There was a problem hiding this comment.
Record post-replace selections for history
When Replace/Replace All records the edit with updateHistory but only provides selectionsBefore, the edit stack stores selectionsAfter as undefined; after a user replaces a match, undoes it, and then redoes it, redo() calls #applyChange without selections and the editor keeps the stale pre-redo selection/caret. Compute and pass the collapsed/next selection (or set it on the undo entry) so redo restores a valid editor state.
Useful? React with 👍 / 👎.
| const re = new RegExp(pattern.source, pattern.flags.replace('g', '')); | ||
| const match = re.exec(matched); | ||
| if (match === null || match[0].length !== matched.length) { | ||
| return searchParams.replaceText; |
There was a problem hiding this comment.
Preserve regex context when expanding replacements
For regexes whose match depends on context outside the consumed text, search still finds the match, but replacement expansion reruns the pattern against only matched. For example (?<=foo)(bar) on foobar matches [3,6], but re.exec('bar') fails here, so $1/$& are inserted literally instead of expanding. Run the regex against the full line at the original index, or carry the original match result from search, before expanding the replacement.
Useful? React with 👍 / 👎.
Uh oh!
There was an error while loading. Please reload this page.