DOM events
↓ (keydown, keypress, input, etc)
public API saneKeyboardEvents
↓ ↓ (keystroke, typedText)
service (typing etc) + edit tree + cursor position + config
↓ (moveInto, selectOutOf, write, etc)
command (next to the cursor) + config
↓ (tree diff + new cursor position)
core (applies tree diff (which modifies displayed math), updates cursor position)
This is actually pretty close to what we have, the main change is that currently commands call tree manipulation methods provided by the core that have difficult-to-use contracts, and if those contracts aren't followed, you end up with a malformed tree/cursor. Going forward, at a minimum the API used by commands cannot malform the tree; if feasible, I'd love if instead of crawling across the tree node-by-node, the command can just pattern-match against the tree, and then (as a pure function) return a diff, using the same diff format/API as we'll use for OT.
Re keystroke
specifically: currently Controller::keystroke()
calls Node::keystroke()
which then calls Controller::backspace()
/::selectLeft()
/etc which in turn call Node::deleteTowards()
/::selectTowards()
/etc, which is pretty weird. This is actually just because math mode and text mode behave differently on space (and it can't be in typedText()
/write()
because math mode needs to distinguish between Spacebar
and Shift-Spacebar
), and because LatexCommandInput
behaves specially on Tab
/Enter
/Spacebar
. At the time I was, naturally, unsure how that would generalize, but thinking on it now, I can't imagine a block node overriding Backspace
in a way incompatible with .deleteOutOf()
. (Well, except someone overriding moveDir()
for invalid positions at the end of a block for "inline" blocks, maybe?)