heyman / heynote

A dedicated scratchpad for developers
https://heynote.com
Other
3.87k stars 194 forks source link

CHORE: Added functionality for basic custom language keymaps. #129

Open feh-pined0 opened 8 months ago

feh-pined0 commented 8 months ago

Based on issue request #116, i tried to implement a basic form of custom keymaps based on the current active note block. The idea is to have a set of custom keymaps for each language type, and for the system to be basic enough to be easily extended.

Although it is not finished yet (maybe add more checks in the transactions, as to not interfer with other blocks), maybe it's a good start if this is a desired feature. #116

heyman commented 8 months ago

I want to refactor the code that handles key bindings to support fully user-customized key bindings. When that is implemented, the custom key bindings functionality should support binding keys that are only active in certain block modes.

However, implementing #116 with the current (somewhat messy) state of key bindings, I think a better approach would be to always bind the commands (with a high precedence). The commands should check if the current block is a Markdown block, and in that case call preventDefault() on the event and do its job, and otherwise not call preventDefault() and return false (allowing other bound commands to handle the event).

So the commands should have a signature that looks something like formatBold({state, dispatch}, event). This would also have the added benefit that one could make the commands work with multiple cursors (you would have to check the type of block at each cursor, and if it's Markdown, perform the action).