Improve editor gadget selection behavior
parent
a61c0d5f7c
commit
204069e01d
|
@ -167,6 +167,12 @@ M: char-elt prev-elt
|
||||||
M: char-elt next-elt
|
M: char-elt next-elt
|
||||||
drop [ drop 1 +col ] (next-char) ;
|
drop [ drop 1 +col ] (next-char) ;
|
||||||
|
|
||||||
|
TUPLE: one-char-elt ;
|
||||||
|
|
||||||
|
M: one-char-elt prev-elt 2drop ;
|
||||||
|
|
||||||
|
M: one-char-elt next-elt 2drop ;
|
||||||
|
|
||||||
: (word-elt) ( loc document quot -- loc )
|
: (word-elt) ( loc document quot -- loc )
|
||||||
pick >r
|
pick >r
|
||||||
>r >r first2 swap r> doc-line r> call
|
>r >r first2 swap r> doc-line r> call
|
||||||
|
|
|
@ -4,7 +4,7 @@ USING: arrays documents ui.clipboards ui.commands ui.gadgets
|
||||||
ui.gadgets.borders ui.gadgets.buttons ui.gadgets.labels
|
ui.gadgets.borders ui.gadgets.buttons ui.gadgets.labels
|
||||||
ui.gadgets.scrollers ui.gadgets.theme ui.render ui.gestures io
|
ui.gadgets.scrollers ui.gadgets.theme ui.render ui.gestures io
|
||||||
kernel math models namespaces opengl opengl.gl sequences strings
|
kernel math models namespaces opengl opengl.gl sequences strings
|
||||||
io.styles math.vectors sorting colors combinators ;
|
io.styles math.vectors sorting colors combinators assocs ;
|
||||||
IN: ui.gadgets.editors
|
IN: ui.gadgets.editors
|
||||||
|
|
||||||
TUPLE: editor
|
TUPLE: editor
|
||||||
|
@ -94,8 +94,11 @@ M: editor ungraft*
|
||||||
rot editor-line x>offset ,
|
rot editor-line x>offset ,
|
||||||
] { } make ;
|
] { } make ;
|
||||||
|
|
||||||
|
: clicked-loc ( editor -- loc )
|
||||||
|
[ hand-rel ] keep point>loc ;
|
||||||
|
|
||||||
: click-loc ( editor model -- )
|
: click-loc ( editor model -- )
|
||||||
>r [ hand-rel ] keep point>loc r> set-model ;
|
>r clicked-loc r> set-model ;
|
||||||
|
|
||||||
: focus-editor ( editor -- )
|
: focus-editor ( editor -- )
|
||||||
t over set-editor-focused? relayout-1 ;
|
t over set-editor-focused? relayout-1 ;
|
||||||
|
@ -244,11 +247,37 @@ M: editor user-input*
|
||||||
|
|
||||||
M: editor gadget-text* editor-string % ;
|
M: editor gadget-text* editor-string % ;
|
||||||
|
|
||||||
: start-selection ( editor -- )
|
|
||||||
dup editor-caret click-loc ;
|
|
||||||
|
|
||||||
: extend-selection ( editor -- )
|
: extend-selection ( editor -- )
|
||||||
dup request-focus start-selection ;
|
dup request-focus dup editor-caret click-loc ;
|
||||||
|
|
||||||
|
: mouse-elt ( -- elelement )
|
||||||
|
hand-click# get {
|
||||||
|
{ 2 T{ one-word-elt } }
|
||||||
|
{ 3 T{ one-line-elt } }
|
||||||
|
} at T{ one-char-elt } or ;
|
||||||
|
|
||||||
|
: drag-direction? ( loc editor -- ? )
|
||||||
|
editor-mark* <=> 0 < ;
|
||||||
|
|
||||||
|
: drag-selection-caret ( loc editor element -- loc )
|
||||||
|
>r [ drag-direction? ] 2keep
|
||||||
|
gadget-model
|
||||||
|
r> prev/next-elt ? ;
|
||||||
|
|
||||||
|
: drag-selection-mark ( loc editor element -- loc )
|
||||||
|
>r [ drag-direction? not ] 2keep
|
||||||
|
nip dup editor-mark* swap gadget-model
|
||||||
|
r> prev/next-elt ? ;
|
||||||
|
|
||||||
|
: drag-caret&mark ( editor -- caret mark )
|
||||||
|
dup clicked-loc swap mouse-elt
|
||||||
|
[ drag-selection-caret ] 3keep
|
||||||
|
drag-selection-mark ;
|
||||||
|
|
||||||
|
: drag-selection ( editor -- )
|
||||||
|
dup drag-caret&mark
|
||||||
|
pick editor-mark set-model
|
||||||
|
swap editor-caret set-model ;
|
||||||
|
|
||||||
: editor-cut ( editor clipboard -- )
|
: editor-cut ( editor clipboard -- )
|
||||||
dupd gadget-copy remove-selection ;
|
dupd gadget-copy remove-selection ;
|
||||||
|
@ -296,17 +325,10 @@ M: editor gadget-text* editor-string % ;
|
||||||
dup T{ one-word-elt } select-elt
|
dup T{ one-word-elt } select-elt
|
||||||
] unless gadget-selection ;
|
] unless gadget-selection ;
|
||||||
|
|
||||||
: (position-caret) ( editor -- )
|
|
||||||
dup extend-selection
|
|
||||||
dup editor-mark click-loc ;
|
|
||||||
|
|
||||||
: position-caret ( editor -- )
|
: position-caret ( editor -- )
|
||||||
hand-click# get {
|
mouse-elt dup T{ one-char-elt } =
|
||||||
{ 1 [ (position-caret) ] }
|
[ drop dup extend-selection dup editor-mark click-loc ]
|
||||||
{ 2 [ T{ one-word-elt } select-elt ] }
|
[ select-elt ] if ;
|
||||||
{ 3 [ T{ one-line-elt } select-elt ] }
|
|
||||||
[ 2drop ]
|
|
||||||
} case ;
|
|
||||||
|
|
||||||
: insert-newline "\n" swap user-input ;
|
: insert-newline "\n" swap user-input ;
|
||||||
|
|
||||||
|
@ -408,7 +430,7 @@ editor "caret-motion" f {
|
||||||
|
|
||||||
editor "selection" f {
|
editor "selection" f {
|
||||||
{ T{ button-down f { S+ } } extend-selection }
|
{ T{ button-down f { S+ } } extend-selection }
|
||||||
{ T{ drag } start-selection }
|
{ T{ drag } drag-selection }
|
||||||
{ T{ gain-focus } focus-editor }
|
{ T{ gain-focus } focus-editor }
|
||||||
{ T{ lose-focus } unfocus-editor }
|
{ T{ lose-focus } unfocus-editor }
|
||||||
{ T{ delete-action } remove-selection }
|
{ T{ delete-action } remove-selection }
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays assocs kernel math models namespaces
|
USING: arrays assocs kernel math models namespaces
|
||||||
sequences words strings system hashtables math.parser
|
sequences words strings system hashtables math.parser
|
||||||
math.vectors tuples classes ui.gadgets timers combinators ;
|
math.vectors tuples classes ui.gadgets timers combinators.lib ;
|
||||||
IN: ui.gestures
|
IN: ui.gestures
|
||||||
|
|
||||||
: set-gestures ( class hash -- ) "gestures" set-word-prop ;
|
: set-gestures ( class hash -- ) "gestures" set-word-prop ;
|
||||||
|
@ -187,12 +187,11 @@ drag-timer construct-empty drag-timer set-global
|
||||||
|
|
||||||
: multi-click? ( button -- ? )
|
: multi-click? ( button -- ? )
|
||||||
{
|
{
|
||||||
{ [ multi-click-timeout? not ] [ f ] }
|
[ multi-click-timeout? ]
|
||||||
{ [ multi-click-button? not ] [ f ] }
|
[ multi-click-button? ]
|
||||||
{ [ multi-click-position? not ] [ f ] }
|
[ multi-click-position? ]
|
||||||
{ [ multi-click-position? not ] [ f ] }
|
[ multi-click-position? ]
|
||||||
{ [ t ] [ t ] }
|
} && nip ;
|
||||||
} cond nip ;
|
|
||||||
|
|
||||||
: update-click# ( button -- )
|
: update-click# ( button -- )
|
||||||
global [
|
global [
|
||||||
|
|
|
@ -397,8 +397,10 @@ M: windows-ui-backend (close-window)
|
||||||
GetDoubleClickTime double-click-timeout set-global ;
|
GetDoubleClickTime double-click-timeout set-global ;
|
||||||
|
|
||||||
: cleanup-win32-ui ( -- )
|
: cleanup-win32-ui ( -- )
|
||||||
class-name-ptr get-global f UnregisterClass drop
|
class-name-ptr get-global [
|
||||||
class-name-ptr get-global [ free ] when*
|
dup f UnregisterClass drop
|
||||||
|
free
|
||||||
|
] when*
|
||||||
f class-name-ptr set-global ;
|
f class-name-ptr set-global ;
|
||||||
|
|
||||||
: setup-pixel-format ( hdc -- )
|
: setup-pixel-format ( hdc -- )
|
||||||
|
|
Loading…
Reference in New Issue