Repository navigation
Keep the regex in sync when a forward search fails - #6
Merged
Merged
Conversation
When `regex.next()` fails in `find_select_next` (e.g. ICU hits its time limit), the regex was left where the search stopped, while `next_search_offset` already pointed at the start of the search. Searching again with the same offset skipped the reset, resumed from the stale position, wrapped around and re-selected the first match instead of failing again. Move the recovery added for backward searches into `find_regex_next` and use it for both directions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
regex.next()fails infind_select_next(e.g. ICU hits its time limit on catastrophic backtracking), the regex was left where the failed search stopped, whilenext_search_offsetalready pointed at the start of the search. The next search with the same offset skippedregex.reset(), resumed from the stale position, wrapped around and re-selected the first match instead of failing again.With
(a+)+bonab+ 40 ×a+c ab, repeated forward searches alternated between an error and a "successful" re-selection of the first match.Changes
find_regex_next, which resets the regex tonext_search_offsetwhennext()fails, and use it for bothnext()calls infind_select_next.find_select_prev. It replaces the equivalent recovery added in Merge upstream microsoft/edit (up to b7f8322) #5, so both directions now share one code path.test_find_next_error_retries_from_same_position.This also exists in upstream's
find_select_next. A report for upstream has been drafted separately and has not been submitted yet.Testing
cargo test: all tests pass. Withfind_regex_nextreverted to a plainnext(), bothtest_find_next_error_retries_from_same_positionandtest_find_prev_error_keeps_forward_positionfail.cargo clippy --all-targets: no warningscargo fmt --check: clean🤖 Generated with Claude Code