Add a highlightSelectionMatches option to only match whole words #8
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "selection-match-whole-words"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
To reduce the amount of noise when making selections while editing prose (e.g. Markdown), it would be nice to have an option to only match whole words.
This adds a new
wholeWordsboolean option to thehighlightSelectionMatchesextension config. When this option is set, selection matches will only be shown when a) the current selection is a whole word and b) the match is a whole word.https://user-images.githubusercontent.com/14294/155411159-e84b9e54-4367-482e-90b4-d0e6cc46f4f1.mov
@marijnh Feel free to change anything if you can see a better implementation. If this looks like something that could be supported, I can have a go at adding tests.
How could slicing a non-empty range ever provide a falsy value?
Would be simpler to just check
range.emptylater on, instead of defining a variable for itThis looks good. I've added some small notes.
Good point! In the existing code there's an extra
.trim()which could lead to a falsy value, but it's not present here so this check isn't necessary.It does look like
if (range.empty)would have the same effect, good idea.Thanks!
@marijnh I've noticed that the default for the
wholeWordsoption was set totruewhen it should have beenfalse(i.e. opt-in):https://github.com/codemirror/search/pull/8/files#diff-08839338d4e65d03ac32b7deaab9788d7f9615fce7ef1689369702af5bfcccf3R24
Ah, indeed. Attached patch changes that.