Context-sensitive completion for word and vocab names
parent
a998925994
commit
27fd669021
|
@ -68,8 +68,11 @@ IN: tools.completion
|
||||||
[ '[ >lower _ [ completion ] with map rank-completions ] ] bi
|
[ '[ >lower _ [ completion ] with map rank-completions ] ] bi
|
||||||
if-empty ;
|
if-empty ;
|
||||||
|
|
||||||
|
: name-completions ( str seq -- seq' )
|
||||||
|
[ dup name>> ] { } map>assoc completions ;
|
||||||
|
|
||||||
: words-matching ( str -- seq )
|
: words-matching ( str -- seq )
|
||||||
all-words [ dup name>> ] { } map>assoc completions ;
|
all-words name-completions ;
|
||||||
|
|
||||||
: vocabs-matching ( str -- seq )
|
: vocabs-matching ( str -- seq )
|
||||||
vocabs [ dup name>> ] { } map>assoc completions ;
|
dictionary get values name-completions ;
|
|
@ -149,4 +149,10 @@ IN: ui.tools.listener.tests
|
||||||
<gadget> "l" get show-popup
|
<gadget> "l" get show-popup
|
||||||
<gadget> "l" get show-popup
|
<gadget> "l" get show-popup
|
||||||
"l" get hide-popup
|
"l" get hide-popup
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
[ t ] [ { "USING:" "A" "B" "C" } complete-USING:? ] unit-test
|
||||||
|
|
||||||
|
[ f ] [ { "USING:" "A" "B" "C" ";" } complete-USING:? ] unit-test
|
||||||
|
|
||||||
|
[ t ] [ { "X" ";" "USING:" "A" "B" "C" } complete-USING:? ] unit-test
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2005, 2009 Slava Pestov.
|
! Copyright (C) 2005, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: inspector kernel help help.markup io io.styles models
|
USING: inspector kernel help help.markup io io.styles models
|
||||||
strings namespaces parser quotations sequences vocabs words
|
strings splitting namespaces parser quotations sequences vocabs words
|
||||||
continuations prettyprint listener debugger threads boxes
|
continuations prettyprint listener debugger threads boxes
|
||||||
concurrency.flags math arrays generic accessors combinators
|
concurrency.flags math arrays generic accessors combinators
|
||||||
assocs fry generic.standard.engines.tuple combinators.short-circuit
|
assocs fry generic.standard.engines.tuple combinators.short-circuit
|
||||||
|
@ -42,9 +42,28 @@ completion-popup ;
|
||||||
assoc-stack
|
assoc-stack
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
: complete-IN:/USE:? ( tokens -- ? )
|
||||||
|
2 short tail* { "IN:" "USE:" } intersects? ;
|
||||||
|
|
||||||
|
: chop-; ( seq -- seq' )
|
||||||
|
{ ";" } split1-last [ ] [ ] ?if ;
|
||||||
|
|
||||||
|
: complete-USING:? ( tokens -- ? )
|
||||||
|
chop-; { "USING:" } intersects? ;
|
||||||
|
|
||||||
|
: up-to-caret ( caret document -- string )
|
||||||
|
[ { 0 0 } ] 2dip doc-range ;
|
||||||
|
|
||||||
|
: vocab-completion? ( interactor -- ? )
|
||||||
|
[ editor-caret* ] [ model>> ] bi up-to-caret " \r\n" split
|
||||||
|
{ [ complete-IN:/USE:? ] [ complete-USING:? ] } 1|| ;
|
||||||
|
|
||||||
: <word-model> ( interactor -- model )
|
: <word-model> ( interactor -- model )
|
||||||
[ one-word-elt <element-model> 1/3 seconds <delay> ] keep
|
[ one-word-elt <element-model> 1/3 seconds <delay> ] keep
|
||||||
'[ _ interactor-use assoc-stack ] <filter> ;
|
'[
|
||||||
|
_ dup vocab-completion?
|
||||||
|
[ drop vocab ] [ interactor-use assoc-stack ] if
|
||||||
|
] <filter> ;
|
||||||
|
|
||||||
: <interactor> ( output -- gadget )
|
: <interactor> ( output -- gadget )
|
||||||
interactor new-editor
|
interactor new-editor
|
||||||
|
@ -416,7 +435,7 @@ M: listener-gadget ungraft*
|
||||||
|
|
||||||
! Foo
|
! Foo
|
||||||
USING: summary ui.gadgets.labels ui.gadgets.tables colors ui.render
|
USING: summary ui.gadgets.labels ui.gadgets.tables colors ui.render
|
||||||
ui.gadgets.worlds ui.gadgets.glass tools.completion ui.gadgets splitting ;
|
ui.gadgets.worlds ui.gadgets.glass tools.completion ui.gadgets ;
|
||||||
USE: tools.completion
|
USE: tools.completion
|
||||||
|
|
||||||
: <summary-gadget> ( model -- gadget )
|
: <summary-gadget> ( model -- gadget )
|
||||||
|
@ -468,29 +487,16 @@ completion-popup H{
|
||||||
{ T{ key-down f f "ESC" } [ hide-completion-popup ] }
|
{ T{ key-down f f "ESC" } [ hide-completion-popup ] }
|
||||||
} set-gestures
|
} set-gestures
|
||||||
|
|
||||||
: <word-completion-popup> ( interactor -- table )
|
: show-completion-popup ( interactor quot -- )
|
||||||
[ words-matching ] <completion-popup> ;
|
dupd <completion-popup>
|
||||||
|
|
||||||
: <vocab-completion-popup> ( interactor -- table )
|
|
||||||
[ vocabs-matching ] <completion-popup> ;
|
|
||||||
|
|
||||||
: (show-completion-popup) ( interactor popup -- )
|
|
||||||
[ >>completion-popup ] keep
|
[ >>completion-popup ] keep
|
||||||
[ find-world ] dip
|
[ find-world ] dip
|
||||||
{ 0 0 } show-glass ;
|
{ 0 0 } show-glass ;
|
||||||
|
|
||||||
: complete-IN:/USE:? ( tokens -- ? )
|
|
||||||
2 short tail* { "IN:" "USE:" } intersects? ;
|
|
||||||
|
|
||||||
: complete-USING:? ( tokens -- ? )
|
|
||||||
{ ";" } split1-last nip { "USING:" } intersects? ;
|
|
||||||
|
|
||||||
: vocab-completion? ( interactor -- ? )
|
|
||||||
[ editor-string ] [ editor-caret* ] bi head " " split
|
|
||||||
{ [ complete-IN:/USE:? ] [ complete-USING:? ] } 1|| ;
|
|
||||||
|
|
||||||
: word-completion-popup ( interactor -- )
|
: word-completion-popup ( interactor -- )
|
||||||
dup <word-completion-popup> (show-completion-popup) ;
|
dup vocab-completion?
|
||||||
|
[ vocabs-matching ] [ words-matching ] ?
|
||||||
|
show-completion-popup ;
|
||||||
|
|
||||||
: pass-to-popup? ( gesture interactor -- ? )
|
: pass-to-popup? ( gesture interactor -- ? )
|
||||||
[ [ key-down? ] [ key-up? ] bi or ]
|
[ [ key-down? ] [ key-up? ] bi or ]
|
||||||
|
|
Loading…
Reference in New Issue