Robert
Robert

Reputation: 2812

Racket GUI: how to get rid of Emacs keybindings with framework:text%

Using the Racket GUI framework, I found that the defaults keybindings of the text editor are the same as Emacs. That is said: completely unreasonable for most of applications. In order to activate the contextual menu Copy/Cut/Paste, I use racket:text% from framework. Control + A don't select all the text, but move the caret to the beginning of the line.

https://docs.racket-lang.org/framework/Keymap.html

How to get rid of this craziness and map "Ctrl + A" to "Select All"?

Edit: I was asked for an example, it can be copy/pasted into DrRacket

#lang racket/gui

(require framework)

(define main-frame (new frame%
                        [label  "Test Ctrl+A and Ctrl+E"]
                        [width  640]
                        [height 280]))

(define log-text (new editor-canvas%
                      [label  #f]
                      [vert-margin 10]
                      [parent main-frame]))

;; rich text editor
(define text-editor (new racket:text%))

(send log-text set-editor text-editor)
(send text-editor insert (format "Test Ctrl+A and Ctrl+E here"))

(send main-frame show #t)

Edit: in DrRacket Ctrl+A select all the text, as expected.

Upvotes: 0

Views: 179

Answers (1)

Leif Andersen
Leif Andersen

Reputation: 22342

Racket's GUI editors have a keymap which can be set with set-keymap. A editor with a keymap with Ctr+A bound to select all can be found in keymap:get-editor. So if you add the line:

(send text-editor set-keymap (keymap:get-editor))

to your code it should change the key bindings from Ctr+A going to the beginning of the line, to highlighting everything.

#lang racket/gui

(require framework)

(define main-frame (new frame%
                        [label  "Test Ctrl+A and Ctrl+E"]
                        [width  640]
                        [height 280]))

(define log-text (new editor-canvas%
                      [label  #f]
                      [vert-margin 10]
                      [parent main-frame]))

;; rich text editor
(define text-editor (new racket:text%))
(send text-editor set-keymap (keymap:get-editor))

(send log-text set-editor text-editor)
(send text-editor insert (format "Test Ctrl+A and Ctrl+E here"))

(send main-frame show #t)

Upvotes: 1

Related Questions