Add CHAR: completion to UI listener

db4
Slava Pestov 2009-02-02 15:58:09 -06:00
parent 2a74c6d113
commit 3eb5222186
3 changed files with 27 additions and 10 deletions

View File

@ -3,7 +3,7 @@
USING: accessors kernel arrays sequences math namespaces USING: accessors kernel arrays sequences math namespaces
strings io fry vectors words assocs combinators sorting strings io fry vectors words assocs combinators sorting
unicode.case unicode.categories math.order vocabs unicode.case unicode.categories math.order vocabs
tools.vocabs ; tools.vocabs unicode.data ;
IN: tools.completion IN: tools.completion
: (fuzzy) ( accum ch i full -- accum i ? ) : (fuzzy) ( accum ch i full -- accum i ? )
@ -76,3 +76,6 @@ IN: tools.completion
: vocabs-matching ( str -- seq ) : vocabs-matching ( str -- seq )
all-vocabs-seq name-completions ; all-vocabs-seq name-completions ;
: chars-matching ( str -- seq )
name-map keys dup zip completions ;

View File

@ -7,7 +7,7 @@ sequences tools.completion generic generic.standard.engines.tuple
fonts ui.commands ui.operations ui.gadgets ui.gadgets.editors fonts ui.commands ui.operations ui.gadgets ui.gadgets.editors
ui.gadgets.glass ui.gadgets.scrollers ui.gadgets.tables ui.gadgets.glass ui.gadgets.scrollers ui.gadgets.tables
ui.gadgets.theme ui.gadgets.worlds ui.gadgets.wrappers ui.gestures ui.gadgets.theme ui.gadgets.worlds ui.gadgets.wrappers ui.gestures
ui.render ui.tools.listener.history ; ui.render ui.tools.listener.history combinators ;
IN: ui.tools.listener.completion IN: ui.tools.listener.completion
: complete-IN:/USE:? ( tokens -- ? ) : complete-IN:/USE:? ( tokens -- ? )
@ -19,12 +19,21 @@ IN: ui.tools.listener.completion
: complete-USING:? ( tokens -- ? ) : complete-USING:? ( tokens -- ? )
chop-; { "USING:" } intersects? ; chop-; { "USING:" } intersects? ;
: complete-CHAR:? ( tokens -- ? )
2 short tail* "CHAR:" swap member? ;
: up-to-caret ( caret document -- string ) : up-to-caret ( caret document -- string )
[ { 0 0 } ] 2dip doc-range ; [ { 0 0 } ] 2dip doc-range ;
: vocab-completion? ( interactor -- ? ) SINGLETONS: word-completion vocab-completion char-completion ;
: completion-mode ( interactor -- symbol )
[ editor-caret ] [ model>> ] bi up-to-caret " \r\n" split [ editor-caret ] [ model>> ] bi up-to-caret " \r\n" split
{ [ complete-IN:/USE:? ] [ complete-USING:? ] } 1|| ; {
{ [ dup { [ complete-IN:/USE:? ] [ complete-USING:? ] } 1|| ] [ drop vocab-completion ] }
{ [ dup complete-CHAR:? ] [ drop char-completion ] }
[ drop word-completion ]
} cond ;
! We don't directly depend on the listener tool but we use a few slots ! We don't directly depend on the listener tool but we use a few slots
SLOT: completion-popup SLOT: completion-popup
@ -133,8 +142,11 @@ CONSTANT: completion-popup-offset { -4 0 }
show-glass ; show-glass ;
: code-completion-popup ( interactor -- ) : code-completion-popup ( interactor -- )
dup vocab-completion? dup completion-mode {
[ vocabs-matching ] [ words-matching ] ? '[ [ { } ] _ if-empty ] { word-completion [ words-matching ] }
{ vocab-completion [ vocabs-matching ] }
{ char-completion [ chars-matching ] }
} at '[ [ { } ] _ if-empty ]
one-word-elt show-completion-popup ; one-word-elt show-completion-popup ;
: history-matching ( interactor -- alist ) : history-matching ( interactor -- alist )

View File

@ -46,9 +46,11 @@ completion-popup ;
{ [ vocab ] [ find-vocab-root ] } 1|| ; { [ vocab ] [ find-vocab-root ] } 1|| ;
: word-at-caret ( token interactor -- word/vocab/f ) : word-at-caret ( token interactor -- word/vocab/f )
dup vocab-completion? dup completion-mode {
[ drop dup vocab-exists? [ >vocab-link ] [ drop f ] if ] { vocab-completion [ drop dup vocab-exists? [ >vocab-link ] [ drop f ] if ] }
[ interactor-use assoc-stack ] if ; { word-completion [ interactor-use assoc-stack ] }
{ char-completion [ 2drop f ] }
} case ;
: <word-model> ( interactor -- model ) : <word-model> ( interactor -- model )
[ token-model>> 1/3 seconds <delay> ] [ token-model>> 1/3 seconds <delay> ]