Add a highlightSelectionMatches option to only match whole words #8

Merged
hubgit merged 4 commits from selection-match-whole-words into main 2022-02-25 11:45:23 +01:00
hubgit commented 2022-02-23 22:03:30 +01:00 (Migrated from github.com)

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 wholeWords boolean option to the highlightSelectionMatches extension 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

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 `wholeWords` boolean option to the `highlightSelectionMatches` extension 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
hubgit commented 2022-02-23 22:04:19 +01:00 (Migrated from github.com)

@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.

@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.
marijnh (Migrated from github.com) reviewed 2022-02-25 10:20:57 +01:00
marijnh (Migrated from github.com) commented 2022-02-25 10:20:57 +01:00

How could slicing a non-empty range ever provide a falsy value?

How could slicing a non-empty range ever provide a falsy value?
marijnh (Migrated from github.com) reviewed 2022-02-25 10:21:47 +01:00
marijnh (Migrated from github.com) commented 2022-02-25 10:21:47 +01:00

Would be simpler to just check range.empty later on, instead of defining a variable for it

Would be simpler to just check `range.empty` later on, instead of defining a variable for it
marijnh commented 2022-02-25 10:22:28 +01:00 (Migrated from github.com)

This looks good. I've added some small notes.

This looks good. I've added some small notes.
hubgit (Migrated from github.com) reviewed 2022-02-25 10:51:42 +01:00
hubgit (Migrated from github.com) commented 2022-02-25 10:51:41 +01:00

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.

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.
hubgit (Migrated from github.com) reviewed 2022-02-25 10:52:41 +01:00
hubgit (Migrated from github.com) commented 2022-02-25 10:52:41 +01:00

It does look like if (range.empty) would have the same effect, good idea.

It does look like `if (range.empty)` would have the same effect, good idea.
marijnh commented 2022-02-25 11:45:28 +01:00 (Migrated from github.com)

Thanks!

Thanks!
hubgit commented 2022-04-05 15:26:53 +02:00 (Migrated from github.com)

@marijnh I've noticed that the default for the wholeWords option was set to true when it should have been false (i.e. opt-in):

https://github.com/codemirror/search/pull/8/files#diff-08839338d4e65d03ac32b7deaab9788d7f9615fce7ef1689369702af5bfcccf3R24

@marijnh I've noticed that the default for the `wholeWords` option was set to `true` when it should have been `false` (i.e. opt-in): https://github.com/codemirror/search/pull/8/files#diff-08839338d4e65d03ac32b7deaab9788d7f9615fce7ef1689369702af5bfcccf3R24
marijnh commented 2022-04-07 08:17:19 +02:00 (Migrated from github.com)

Ah, indeed. Attached patch changes that.

Ah, indeed. Attached patch changes that.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/search!8
No description provided.