The structural straitjacket of ve.ce.Surface#handleObservedChanges has provoked some contorted escapology:
- It handles content changes before range changes (escaped by catapulting to some vague future moment with setTimeout)
- It infers prior cursor positions with respect to annotations by looking at the state at the last keydown event; but there may not have *been* a keydown event (e.g. with IME text input).
- It hides central pure functional logic (building transactions from observed state changes) inside a method that has side effects, forcing some contortion on unit tests.
Refactor it to be clearer, mundaner and less heroic.