Le 09/04/2016 15:15, Robby Findler a écrit :
Does this code help?


It works, but the problem is there is no ways to choose which funcs I want to include in a keymap, I must include them all :, and I don't want emacs or open/save file keybindings...

I finally took some codes from the link i've posted, to only add one-word-selection. I think these keymaps should be included by default in text% objects (framework:get-editor and mouse selections).

However my problem is now fixed, thanks you and Matthew Flatt.


-------------------

(define textField%
  (class text-field%
    (super-new)
    (define keymap (keymap:get-editor))

    ;; Useful mouse functions
    (define (region-click edit event f)
      (when (and (send event button-down?)
                 (is-a? edit text%))
        (let ([x-box (box (send event get-x))]
              [y-box (box (send event get-y))]
              [eol-box (box #f)])
          (send edit global-to-local x-box y-box)
          (let ([click-pos (send edit find-position
                                 (unbox x-box)
                                 (unbox y-box)
                                 eol-box)]
                [start-pos (send edit get-start-position)]
                [end-pos (send edit get-end-position)])
            (let ([eol (unbox eol-box)])
              (if (< start-pos click-pos)
                  (f click-pos eol start-pos click-pos)
                  (f click-pos eol click-pos end-pos)))))))
    (define (select-click-word edit event)
      (region-click edit event
                    (lambda (click eol start end)
                      (let ([start-box (box click)]
                            [end-box (box click)])
                        (send edit find-wordbreak
                              start-box
                              end-box
                              'selection)
                        (send edit set-position
                              (unbox start-box)
                              (unbox end-box))))))

    (define (select-all edit event)
      (send edit select-all))
    (keymap:setup-editor keymap)

    ;; Adding functions to keymap object
    (send keymap add-function "select-click-word" select-click-word)
    (send keymap map-function "leftbuttondouble" "select-click-word")
    (send keymap add-function "select-all" select-all)
    (send keymap map-function "leftbuttontriple" "select-all")

    (send (send this get-editor) set-keymap keymap)))



--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to