How to fire autocorrects, keeping load low

Hey there,
for a project i’m using Codemirror because it’s just awesome in its extensibility and ease of use.

I’d like to make sure that i’m not overlooking something stupid and/or super simple.

For this project, I have a key=>value array that has a long list of autocorrects that have to be replaced at any time when they’re the last word that has been typed.

So to do that, I use
editor.on('keyup', function() { runAutoreplace()
where the runAutoreplace() runs along the lines of:

  • get the sentence where the cursor is
  • get the last word typed by the user
  • check if that word is a key in the array of replacements
  • if so, replace
  • then set the entire line to be that new replacement sentence.

It works fine, but i’m pondering if there maybe is a better solution to this.