Running mode tokenizer on existing text

Consider a mode with a token function. I create a CM and load my text into it with setValue. How can I force the mode to run on the entire text (all tokens) one time after the text is set ?

thx!

This sounds like you’e abusing modes for things they aren’t good at. But if you must, you can call getStateAfter(null, true) to get the state produced by running the mode over the whole file.

hmmm … this did not work

I am using the spell checker from https://github.com/NextStepWebs/codemirror-spell-checker

Basically it has a simple mode with a token function that checks if the word is in the dictionary and if yes adds a css class which sets a background to the word.

See the mode code here: https://github.com/NextStepWebs/codemirror-spell-checker/commit/9a12aff3088c82615e610d2ba0e04635d1b26361

As you can see in the demo (http://nextstepwebs.github.io/codemirror-spell-checker/), typos are not highlighted intially, only after you make the first edit.

As far as I can tell this is because the mode does not make an intial pass over the text so I’m looking for a way to intiate such a pass.

getStateAfter(null, true) did not work.

Any help ?

Modes are run, immediately, on all visible content. So if the mode isn’t highlighting, the problem is elsewhere.

you’re right, figured it out … the dict was loaded asynchronously before the mode’s first pass … thx!

marjin, this presents various issues for me which can be solved much simpler if I can tell CM to re-run the mode over a particular line.

Is there any way to do that ?

Not per-line, but you can force a full re-run of your mode by setting the "mode" option (even if it is set to the same value).