Bogdanp / racket-gui-easy

Declarative GUIs in Racket.
https://docs.racket-lang.org/gui-easy/index.html
134 stars 18 forks source link

Default keymap for (input) should be (keymap:get-editor) #30

Closed cloudrac3r closed 1 year ago

cloudrac3r commented 1 year ago

The current default is to have no keybinds, but I don't think this is very helpful. We all expect Ctrl+C/Ctrl+V et al to be available everywhere!

(keymap:get-editor) includes all the keybinds that I would expect for a plain text field and it makes sense as a default.

This would save me a couple lines of code and memorisation each time I make a little application with gui-easy :)

Bogdanp commented 1 year ago

This used to be the default, but I dropped it because framework takes a couple seconds to load, so it was annoying when writing small tools. I agree that not having those keybindings is also annoying in its own right, though. Would you be willing to add some of the basic keybindings for your platform to "gui/easy/private/view/keymap.rkt"? If not, I can probably take care of it later this week.

cloudrac3r commented 1 year ago

Oh, that's interesting. I've never personally noticed that framework takes additional time to load, but I believe you.

Would you be willing to add some of the basic keybindings for your platform to "gui/easy/private/view/keymap.rkt"?

I can test on Linux and Windows. I'll take a look and see what I can do!

cloudrac3r commented 1 year ago

I came up with this for my Linux computer:

(case (system-type 'os)
  [(macosx)
   (add&map "c:a" 'goto-start (λ (editor _event)
                                (send editor set-position 0)))
   (add&map "c:e" 'goto-end (λ (editor _event)
                              (send editor set-position (send editor last-position))))
   (add&map "d:a" 'select-all (λ (editor _event)
                                (send editor do-edit-operation 'select-all)))]
  [(unix)
   (add&map ":c:a" 'select-all (λ (editor _event)
                                (send editor do-edit-operation 'select-all)))
   (add&map ":c:z" 'undo (λ (editor _event)
                          (send editor do-edit-operation 'undo)))
   (add&map ":c:Z" 'redo (λ (editor _event)
                            (send editor do-edit-operation 'redo)))
   (add&map ":c:x" 'cut (λ (editor _event)
                         (send editor do-edit-operation 'cut)))
   (add&map ":c:c" 'copy (λ (editor _event)
                          (send editor do-edit-operation 'copy)))
   (add&map ":c:v" 'paste (λ (editor _event)
                           (send editor do-edit-operation 'paste)))])

However, undo and redo don't seem to fully work. I think the keybinds are activating but the editor is not recording the undo/redo history correctly, and I need to go to bed rather than debugging this right now. It would also be a nice-to-have if Ctrl+Left, Ctrl+Right, Alt+Left, Alt+Right moved the cursor backward and forward one word, which there doesn't seem to be a built in method for. At least cut/copy/paste all work.

Bogdanp commented 1 year ago

I've pushed a change to incorporate your examples, and I think I got undo and redo working. I think the word movement commands probably can also be implemented using find-wordbreak, but I'll have to look at that some other time.

Bogdanp commented 1 year ago

I've pushed another update to support moving backward and forward by word. I think that covers the basics, but do let me know if one of the Windows/Linux bindings is wrong or if there are others we should add.

cloudrac3r commented 1 year ago

Works great on Windows, great job :)