isearch - End highlight when no range found #1725
Merged
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.
Background
I started looking into this from: In vi mode :'<,'>s/^/;;/ leads to a crash.
It was a windy road to find this small code change, but I think this has the smallest impact, and works. I learned a lot about vi-mode ex-commands and isearch.
Cause
When using the isearch mode:
*isearch-search-forward-function* = lem:search-forward-regexp
, which vi-mode ex-command substitute does, the editor freezes when attempting to highlight regex that evaluates to an empty string. Eg. "^", "$", both can be searched for, but should not highlight anything.This is because in
isearch:highlight-region
, for example with "^", the loop searches backward for "^", then the end loop clause searches forward in the line for "^" and does not find it, so it loops infinitely, and causes Lem to freeze. Same with "$", ".*", etc.Fix
Add to the loop end clause, that if after the points have been moved by these above checks, if the mutable moving start-point = end-point still, then end the highlighting loop as there is nothing to highligh.
Testing
I added tests to vi-mode and verified the isearch ones still pass.
Tested myself via vi-mode subs, and verified isearch still works.
Vi-mode "/" and "?" still highlight correctly.