diff --git a/basis/tools/completion/completion.factor b/basis/tools/completion/completion.factor index 47977b45c1..14cec8e85f 100644 --- a/basis/tools/completion/completion.factor +++ b/basis/tools/completion/completion.factor @@ -3,7 +3,7 @@ USING: accessors kernel arrays sequences math namespaces strings io fry vectors words assocs combinators sorting unicode.case unicode.categories math.order vocabs -tools.vocabs ; +tools.vocabs unicode.data ; IN: tools.completion : (fuzzy) ( accum ch i full -- accum i ? ) @@ -75,4 +75,7 @@ IN: tools.completion all-words name-completions ; : vocabs-matching ( str -- seq ) - all-vocabs-seq name-completions ; \ No newline at end of file + all-vocabs-seq name-completions ; + +: chars-matching ( str -- seq ) + name-map keys dup zip completions ; \ No newline at end of file diff --git a/basis/ui/tools/listener/completion/completion.factor b/basis/ui/tools/listener/completion/completion.factor index 5bb59b6b21..5cfabf7697 100644 --- a/basis/ui/tools/listener/completion/completion.factor +++ b/basis/ui/tools/listener/completion/completion.factor @@ -7,7 +7,7 @@ sequences tools.completion generic generic.standard.engines.tuple fonts ui.commands ui.operations ui.gadgets ui.gadgets.editors ui.gadgets.glass ui.gadgets.scrollers ui.gadgets.tables 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 : complete-IN:/USE:? ( tokens -- ? ) @@ -19,12 +19,21 @@ IN: ui.tools.listener.completion : complete-USING:? ( tokens -- ? ) chop-; { "USING:" } intersects? ; +: complete-CHAR:? ( tokens -- ? ) + 2 short tail* "CHAR:" swap member? ; + : up-to-caret ( caret document -- string ) [ { 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 - { [ 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 SLOT: completion-popup @@ -133,8 +142,11 @@ CONSTANT: completion-popup-offset { -4 0 } show-glass ; : code-completion-popup ( interactor -- ) - dup vocab-completion? - [ vocabs-matching ] [ words-matching ] ? '[ [ { } ] _ if-empty ] + dup completion-mode { + { word-completion [ words-matching ] } + { vocab-completion [ vocabs-matching ] } + { char-completion [ chars-matching ] } + } at '[ [ { } ] _ if-empty ] one-word-elt show-completion-popup ; : history-matching ( interactor -- alist ) diff --git a/basis/ui/tools/listener/listener.factor b/basis/ui/tools/listener/listener.factor index c064906f70..e6039a4da5 100644 --- a/basis/ui/tools/listener/listener.factor +++ b/basis/ui/tools/listener/listener.factor @@ -46,9 +46,11 @@ completion-popup ; { [ vocab ] [ find-vocab-root ] } 1|| ; : word-at-caret ( token interactor -- word/vocab/f ) - dup vocab-completion? - [ drop dup vocab-exists? [ >vocab-link ] [ drop f ] if ] - [ interactor-use assoc-stack ] if ; + dup completion-mode { + { vocab-completion [ drop dup vocab-exists? [ >vocab-link ] [ drop f ] if ] } + { word-completion [ interactor-use assoc-stack ] } + { char-completion [ 2drop f ] } + } case ; : ( interactor -- model ) [ token-model>> 1/3 seconds ]