I'm attempting to create a editor with Draft.js which will highlight specific words as the user types them, however I've been running into a bug where if the same highlighted word is typed back to back separated by a single space it will cause the highlighted substring to be appended to the end of the previous editor content for one state update (content returns to expected value upon the next editor state update).
I have found that in findWithRegex()
, if I set end
the match array length +/- 1 e.g. end = start + matchArr[0].length + 1;
it resolves the issue, it seems to be something with setting end
to the exact length of the substring.
CodeSandbox: https://codesandbox.io/s/throbbing-thunder-fp2rx8?file=/src/App.tsx ("doe" is the highlight word in this example)
I'm writing this at 1 AM so I hope my issue makes sense haha, please ask any questions you might have. Thanks in advance!