react-highlight-words icon indicating copy to clipboard operation
react-highlight-words copied to clipboard

Adjacent active chunks are handled as a single chunk

Open grigasp opened this issue 6 years ago • 2 comments

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.

grigasp avatar Dec 04 '18 06:12 grigasp

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?

bvaughn avatar Dec 04 '18 16:12 bvaughn

Here's a demo of the issue:

https://codesandbox.io/s/14nx7w1404

bigappleinsider avatar Jan 12 '19 01:01 bigappleinsider