Replies: 6 comments
-
I see that code highlighting is implemented by processing each node:
but in my case text may be split across nodes. |
Beta Was this translation helpful? Give feedback.
-
This is kind of a tricky one, actually. You could do a $nodesOfType to get all TextNodes, then you'd need to check their content, find instances of the word you're looking for, get the start and end offsets of that instance, createRangeSelection from that, then $wrapSelectionInMarkNodes. That's the best I can think of at the moment. |
Beta Was this translation helpful? Give feedback.
-
Did you already find a solution for this? I found this article from Logrocket that seems to do something similar with the CSS higlight api: https://blog.logrocket.com/getting-started-css-custom-highlight-api/ Maybe we can do something similar? |
Beta Was this translation helpful? Give feedback.
-
I am still looking for a solution to this problem - would be happy to get an update if possible |
Beta Was this translation helpful? Give feedback.
-
Yeah this is also an area that I'm going to need a solution for soon. It would be awesome if there was a lexical plugin for this 🤔 |
Beta Was this translation helpful? Give feedback.
-
This answer Might help_!_ |
Beta Was this translation helpful? Give feedback.
-
I need to implement a toggleable highlighting of certain words, for example, highlighting all instances of the word "hello" when a button is pressed. This is a stepping stone to implementing something like customized document search, for example.
Applying highlights via
$wrapSelectionInMarkNode
is not bad, but I'm struggling to figure out how to get the right selection data to pass into this function.What would be your suggestion for the golden path here? Thank you so much! Have been having a blast with Lexical so far.
Beta Was this translation helpful? Give feedback.
All reactions