diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 81439e4519..5174c03839 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -24,7 +24,6 @@ - fix top level window positioning - services do not launch if factor not running - editor: - - double/triple click - autoscroll - transpose char/word/line - more efficient multi-line inserts diff --git a/library/ui/cocoa/view-utils.factor b/library/ui/cocoa/view-utils.factor index 3b3d22f464..56040cf46d 100644 --- a/library/ui/cocoa/view-utils.factor +++ b/library/ui/cocoa/view-utils.factor @@ -91,11 +91,16 @@ opengl sequences ; : mouse-event>gesture ( event -- modifiers button ) dup event-modifiers swap button ; +: update-click-count ( event -- ) + -> clickCount 1 max hand-click# set-global ; + : send-button-down$ ( view event -- ) + [ update-click-count ] keep [ mouse-event>gesture ] 2keep mouse-location rot window send-button-down ; : send-button-up$ ( view event -- ) + [ update-click-count ] keep [ mouse-event>gesture ] 2keep mouse-location rot window send-button-up ; diff --git a/library/ui/test/editor.factor b/library/ui/test/editor.factor index 49b671ce0f..6f0a264f6e 100644 --- a/library/ui/test/editor.factor +++ b/library/ui/test/editor.factor @@ -8,3 +8,21 @@ gadgets ; "editor" get editor-text [ \ = see ] string-out = "editor" get ungraft* ] unit-test + +[ "foo bar" ] [ + "editor" set + "editor" get graft* + "foo bar" "editor" get set-editor-text + "editor" get T{ one-line-elt } select-elt + "editor" get gadget-selection + "editor" get ungraft* +] unit-test + +[ "baz quux" ] [ + "editor" set + "editor" get graft* + "foo bar\nbaz quux" "editor" get set-editor-text + "editor" get T{ one-line-elt } select-elt + "editor" get gadget-selection + "editor" get ungraft* +] unit-test diff --git a/library/ui/text/commands.factor b/library/ui/text/commands.factor index 93794d78f3..9d9f083dd7 100644 --- a/library/ui/text/commands.factor +++ b/library/ui/text/commands.factor @@ -1,16 +1,12 @@ ! Copyright (C) 2006 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. IN: gadgets-text -USING: gadgets kernel models namespaces sequences ; +USING: gadgets kernel models namespaces sequences arrays ; : editor-extend-selection ( editor -- ) dup request-focus dup editor-caret click-loc ; -: editor-mouse-down ( editor -- ) - dup editor-extend-selection - dup editor-mark click-loc ; - : editor-mouse-drag ( editor -- ) dup editor-caret click-loc ; @@ -70,6 +66,18 @@ USING: gadgets kernel models namespaces sequences ; [ dup T{ word-elt } select-elt ] unless gadget-selection ; +: position-caret ( editor -- ) + dup editor-extend-selection + dup editor-mark click-loc ; + +: editor-mouse-down ( editor -- ) + hand-click# get { + [ ] + [ dup position-caret ] + [ dup T{ word-elt } select-elt ] + [ dup T{ one-line-elt } select-elt ] + } ?nth call drop ; + editor "editing" { { "Insert newline" T{ key-down f f "RETURN" } [ "\n" swap user-input ] } { "Insert newline" T{ key-down f { S+ } "RETURN" } [ "\n" swap user-input ] } diff --git a/library/ui/text/elements.factor b/library/ui/text/elements.factor index fabcf1bcec..bac411fdbb 100644 --- a/library/ui/text/elements.factor +++ b/library/ui/text/elements.factor @@ -1,5 +1,5 @@ IN: gadgets-text -USING: arrays kernel math sequences strings ; +USING: arrays kernel math sequences strings models ; GENERIC: prev-elt ( loc document elt -- loc ) GENERIC: next-elt ( loc document elt -- loc )