 : hide-completion-popup ( popup -- )
     find-world hide-glass ;
 
-: completion-loc/doc ( popup -- loc doc )
-    interactor>> [ editor-caret ] [ model>> ] bi ;
+: completion-loc/doc/elt ( popup -- loc doc elt )
+    [ interactor>> [ editor-caret ] [ model>> ] bi ]
+    [ completion-mode>> completion-element ]
+    bi ;
 
 GENERIC: completion-string ( object -- string )
 

        t >>selection-required?
        dup '[ _ accept-completion ] >>action ;

: <completion-scroller> ( object -- object )
    <limited-scroller>
        { 300 120 } >>min-dim
        { 300 120 } >>max-dim ;

: <completion-popup> ( interactor completion-mode -- popup )
    [ vertical completion-popup new-track ] 2dip
    [ [ >>interactor ] [ >>completion-mode ] bi* ] [ <completion-table> >>table ] 2bi
    dup [ table>> <completion-scroller> ] [ completion-mode>> completion-banner ] bi
    <labelled-gadget> 1 track-add
    COLOR: white <solid> >>interior ;


M: char-completion completion-banner drop "Unicode code point names:" ;
M: history-completion completion-banner drop "Input history:" ;

GENERIC: completion-popup-width ( interactor completion-mode -- x )

M: object completion-popup-width 2drop 300 ;
M: history-completion completion-popup-width drop dim>> first ;

! Completion modes also implement the row renderer protocol
M: listener-completion row-columns drop present 1array ;

