Anti-Adjective Text Editor

Challenge: The editor-content parsing function disrupts UX, because language-processing and API calls both take time to resolve.
Solution: Debounce the function to only run after the user has not typed for two seconds. Then run NLP first, compare the number of adjective-matches to last time, and only if the number of matches has changed, fetch synonyms and rebuild the editor DOM.
Challenge: Every time the language processing function runs and the innerHTML content of the editor is rebuilt, the caret resets to the beginning of the editor.
Solution: An algorithm that cheats by assuming new content the user has typed since last update is behind the current caret position. It counts the DOM nodes backward from the end of the editor content to the current caret postion, and then counts the same way again in the updated DOM.