marijnh/CodeMirror — pull request #1610 by njx (2013-06-13 18:44:35+00:00)
Title: Suggestion for option to `getTokenAt()/getStateBefore()` to improve precision after edits

Because re-highlighting is delayed after an edit, the cached mode state for lines after `doc.frontier` can be invalid. This proposal adds a `precise` option to `getTokenAt()` and `getStateBefore()` that makes them ignore line states after the frontier when trying to find the first valid line.

This doesn't guarantee total accuracy since it will still cut off the search at 100 lines, but it will be at least as accurate as the case where no highlighting had previously been run. (And, in most cases, the thing we're trying to get the token for will be near the last edit point, so it will usually hit the frontier.)

I'm open to other approaches to dealing with this issue, but this seemed the least invasive to me.