Skip to content

Instantly share code, notes, and snippets.

@LeifAndersen
Created October 11, 2019 01:23
Show Gist options
  • Save LeifAndersen/2864448001380826a84d44a4f3225c5c to your computer and use it in GitHub Desktop.
Save LeifAndersen/2864448001380826a84d44a4f3225c5c to your computer and use it in GitHub Desktop.
#lang scratch
(define will-text%
(class text%
(inherit get-position
find-wordbreak
set-position)
(super-new)
(define DOUBLE-CLICK-DELTA 500)
(define last-click 0)
(define highlighting-word #f)
(define/private (select-word)
(define s (box 0))
(define e (box 0))
(get-position s e)
(find-wordbreak s e 'selection)
(set-position (unbox s) (unbox e)))
(define/override (on-event evt)
(super on-event evt)
(case (send evt get-event-type)
[(left-down)
(define new-click (send evt get-time-stamp))
(when (<= (- new-click last-click) DOUBLE-CLICK-DELTA)
(set! highlighting-word #t))
(set! last-click new-click)]
[(left-up)
(set! highlighting-word #f)])
(when highlighting-word
(select-word)))))
(define f (new frame% [label "HI"]
[min-width 500]
[min-height 500]))
(define text (new will-text%))
(send text insert "This is just a small snip of text.")
(new editor-canvas% [parent f]
[editor text])
(send f show #t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment