nim-noise icon indicating copy to clipboard operation
nim-noise copied to clipboard

Allow adding custom keybindings

Open xoich opened this issue 2 years ago • 3 comments

Hello, it seems this is not possible at the moment, but that it could be allowed by enabling the injection of custom procs to the Noise.procs list. Let me know what you think, thank you.

xoich avatar Dec 17 '22 14:12 xoich

well, the current design is using keycode map directly to action code. what we need is adding enum of actions e.g. {...MOVE_LEFT, CUT, COPY, PASTE, MOVE_RIGHT...}. and then map key code to this finite set of actions. but the real challenge is designing new format of the keycode that can be easily and efficiently mapped to actions. worst case we might also need runtime table, but I think it is possible to use simple array if we can arrange it in clever way.

jangko avatar Dec 18 '22 02:12 jangko

customizing the existing keybindings might be needed too, but I was not thinking about that, but about adding new ones:

For example a library user might want to:

  • Add a keybinding to edit the current line in a text editor.
  • If the line represents a LaTeX math formula, one might want a keybinding that previews it by popping up the rendering in a new window.

xoich avatar Dec 18 '22 07:12 xoich

the mechanism to add additional keybinding is already there. you only need to add a public api to make it available to users.

additional keybindings can be put into this EditProc chain.

https://github.com/jangko/nim-noise/blob/d5af2db49a36c01667a58ed27d83352aaa13e0b6/noise.nim#L64

but because nim-noise was designed with simplicity in mind at that time, you need to consider how to handle user data. user data typically can be handled using nim closure, object inheritance, or explicit user data when registering the additional keybinding proc.

jangko avatar Dec 19 '22 09:12 jangko