How does my mode "know" when the last character in a line is deleted?
Say, I type something, and my mode object receives calls to token(stream, state)
as I type. Then if I delete characters one by one, say, by pressing backspace, token
method gets called every time except for when I delete the last character (in which case blankLine
is called).
This is not convenient if I build an AST from the tokens. I need to delete the part of my AST that represented the last deleted character. I could use blankLine
if I could associate it with deletion of the last character, but I cannot find a way.
Please help.
A mode doesn't and shouldn't know about changes to the document. It just parses the stream it was given. But you can have other code listen to
"change"
events, and update data structures used by your mode in response to them.