nothingislost / obsidian-dynamic-highlights

An experimental Obsidian plugin that highlights all occurrences of the word under the cursor
MIT License
134 stars 7 forks source link

Do not highlight with multiple words selected #6

Closed chrisgrieser closed 2 years ago

chrisgrieser commented 2 years ago
Screenshot 2021-12-29 21 09 43

The plugin currently simply selects the first word. However, when I am selecting text, this probably means that I am doing something where highlights do not matter that much anyway, and the extra highlight only adds noise.

Alternatively, the plugin could select both/all words there a selection is, and highlight all occurrences of those two words occurring together, which might also be useful.

nothingislost commented 2 years ago

The new version I'm about to push actually treats a selection as a different highlighting mode. When a selection is active, the text inside the selection will be used as the regex. In this selection mode, there is no word boundary logic, it's a basic string search. This will allow for your sentence use case, as long as you select the full sentence. You could even select the entire paragraph, if you wanted. It won't work across line boundaries though.

nothingislost commented 2 years ago

Addressed in 0.0.5

chrisgrieser commented 2 years ago

nice idea. two suggestions for this one:

nothingislost commented 2 years ago

The selected string styling is also an indicator of whether or not there were any matches found. If your selection is underlined, that means a match was found. You good with not having that?

I assume you'd still want the data attribute containing the text of the selection?

nothingislost commented 2 years ago

Can you describe your use case for the string select ignore list setting?

chrisgrieser commented 2 years ago

The selected string styling is also an indicator of whether or not there were any matches found. If your selection is underlined, that means a match was found. You good with not having that?

Good point. However, a selection always getting additional styling, can also be quite a bit distracting though. not totally sure how to solve this one 🤔

I assume you'd still want the data attribute containing the text of the selection?

sure!

Can you describe your use case for the string select ignore list setting?

Well, by default, the selected-string-highlight should of course ignore the words in the ignore list. However, as opposed to simply having the cursor somewhere, the selection of text is more intentional action by the user. This means that maybe, the user actually does want to search for all occurrences of the word "the" in their text. a setting would allow this kind of flexibility.

(However, I think this is indeed a quite niche use case, so simply having the ignore list always apply would also be fine, I think.)

nothingislost commented 2 years ago

Addressed in 0.0.6

chrisgrieser commented 2 years ago

everything works great!