osric.uk

I'm thinking about how to match commands. If I could guarantee that commands were all single characters with no modifier keys then I'd been happy enough using a hash lookup.

But life is not that simple. "Redo" is Ctrl-r for example. I could write a KeyboardEvent toString method that includes modifier keys in a specific order, and use that as the hash key.

I'm starting to prefer that to the other idea I've had, which is to hand the KeyboardEvent to each command to see who wants it, with each command doing any needed "isCtrlPressed" checks.

But the more I think, the more I like the toString idea. It does most of the computation up front, other than a cheap hash lookup. It's very clear what keystroke is being mapped. And it makes reading in config files much cleaner ("cmd-redo = Ctrl-r").

Calling that decided, commands now have a name ("redo", "delete", "insert-mode"), a keystroke (and a mode for that keystroke?) ("Ctrl-R"/normal, "d"/normal "i"/normal), and an implementation (that can call a getMovement function, and can modify the text buffer).

I think I also want a way to 'script' commands, since "o" is a "d" command followed by an "i" command (although for MVP, I can call the "d" and "i" implementations explicitly.)