react-highlight-words
react-highlight-words copied to clipboard
Adjacent active chunks are handled as a single chunk
See this example: https://codesandbox.io/s/7j2njo9l2q.
searchWords={["e"]}
textToHighlight="sleep"
activeIndex={0}
highlights both ee
instead of just the first e
. With activeIndex={1}
nothing gets highlighted.
Interesting. Looks like this is due to the [highlight-words-core combineChunks
method joining the adjacent chunks before returning them.
I haven't thought about this code in a long time, but my initial thoughts are that the easiest way to fix this would probably be to tell highlight-words-core not to combine chunks if an activeIndex
value is provided. Probably the easiest way to do that is to just pass a no-op findChunks
param to highlight-words-core.
Interested in contributing a PR that does something like this?
Here's a demo of the issue:
https://codesandbox.io/s/14nx7w1404