made the no-completions case work better

svn: r7317
This commit is contained in:
Robby Findler 2007-09-11 15:31:47 +00:00
parent ef7223ab49
commit ec23be9160
2 changed files with 96 additions and 71 deletions

View File

@ -2233,11 +2233,10 @@ designates the character that triggers autocompletion
(let* ([end-pos (get-end-position)] (let* ([end-pos (get-end-position)]
[word (get-word-at end-pos)] [word (get-word-at end-pos)]
[completion-cursor (get-completions word)]) [completion-cursor (get-completions word)])
(when (not (send completion-cursor empty?)) (let ([start-pos (- end-pos (string-length word))])
(let ([start-pos (- end-pos (string-length word))]) (set! word-start-pos start-pos)
(set! word-start-pos start-pos) (set! word-end-pos end-pos)
(set! word-end-pos end-pos) (show-options word start-pos end-pos completion-cursor)))))
(show-options word start-pos end-pos completion-cursor))))))
;; Number -> String ;; Number -> String
;; The word that ends at the current positon of the editor ;; The word that ends at the current positon of the editor
@ -2265,26 +2264,29 @@ designates the character that triggers autocompletion
(define/override (on-char key-event) (define/override (on-char key-event)
(cond (cond
[completions-box [completions-box
(let ([kevt (send key-event get-key-code)]) (let ([code (send key-event get-key-code)]
[full? (not (send completions-box empty?))])
(cond (cond
[(memq kevt '(up wheel-up)) ;; why is on-char not even getting mouse-wheel events? [(and full? (memq code '(up wheel-up)))
(send completions-box prev-item)] (send completions-box prev-item)]
[(or (memq kevt '(down wheel-down)) [(and full?
(completion-mode-key-event? key-event)) (or (memq code '(down wheel-down))
(completion-mode-key-event? key-event)))
(send completions-box next-item)] (send completions-box next-item)]
[(eq? kevt 'prior) (send completions-box scroll-display-up)] [(and full? (eq? code 'prior)) (send completions-box scroll-display-up)]
[(eq? kevt 'next) (send completions-box scroll-display-down)] [(and full? (eq? code 'next)) (send completions-box scroll-display-down)]
[(eq? kevt 'release) [(eq? code 'release)
(void)] (void)]
[(eq? kevt #\backspace) [(eq? code #\backspace)
(widen-possible-completions) (widen-possible-completions)
(super on-char key-event)] (super on-char key-event)]
[(eq? kevt #\return) [(eq? code #\return)
(insert-currently-selected-string) (when full?
(insert-currently-selected-string))
(destroy-completions-box)] (destroy-completions-box)]
[(and (char? kevt) (char-graphic? kevt)) [(and (char? code) (char-graphic? code))
(super on-char key-event) (super on-char key-event)
(constrict-possible-completions kevt)] (constrict-possible-completions code)]
[else [else
(destroy-completions-box) (destroy-completions-box)
(super on-char key-event)]))] (super on-char key-event)]))]
@ -2300,7 +2302,8 @@ designates the character that triggers autocompletion
(let*-values ([(x) (send mouse-event get-x)] (let*-values ([(x) (send mouse-event get-x)]
[(y) (send mouse-event get-y)] [(y) (send mouse-event get-y)]
[(mouse-x mouse-y) (dc-location-to-editor-location x y)]) [(mouse-x mouse-y) (dc-location-to-editor-location x y)])
(if (send completions-box point-inside-menu? mouse-x mouse-y) (if (and (send completions-box point-inside-menu? mouse-x mouse-y)
(not (send completions-box empty?)))
(cond (cond
[(send mouse-event moving?) [(send mouse-event moving?)
(send completions-box handle-mouse-movement mouse-x mouse-y) (send completions-box handle-mouse-movement mouse-x mouse-y)
@ -2316,14 +2319,9 @@ designates the character that triggers autocompletion
(define/private (constrict-possible-completions char) (define/private (constrict-possible-completions char)
(set! word-end-pos (add1 word-end-pos)) (set! word-end-pos (add1 word-end-pos))
(let-values ([(x0 y0 x1 y1) (send completions-box get-menu-coordinates)]) (let-values ([(x0 y0 x1 y1) (send completions-box get-menu-coordinates)])
(let ([box-still-has-elements? (send completions-box narrow char)]) (send completions-box narrow char)
(cond (let-values ([(_ __ x1p y1p) (send completions-box get-menu-coordinates)])
[box-still-has-elements? (invalidate-bitmap-cache x0 y0 (max x1 x1p) (max y1 y1p)))))
(let-values ([(_ __ x1p y1p) (send completions-box get-menu-coordinates)])
(invalidate-bitmap-cache x0 y0 (max x1 x1p) (max y1 y1p)))]
[else
(set! completions-box #f)
(invalidate-bitmap-cache x0 y0 x1 y1)]))))
(define/private (widen-possible-completions) (define/private (widen-possible-completions)
(let-values ([(x0 y0 x1 y1) (send completions-box get-menu-coordinates)]) (let-values ([(x0 y0 x1 y1) (send completions-box get-menu-coordinates)])
@ -2335,7 +2333,7 @@ designates the character that triggers autocompletion
[else [else
(set! completions-box #f) (set! completions-box #f)
(invalidate-bitmap-cache x0 y0 x1 y1)])))) (invalidate-bitmap-cache x0 y0 x1 y1)]))))
;; destroy-completions-box : -> void ;; destroy-completions-box : -> void
;; eliminates the active completions box ;; eliminates the active completions box
(define/private (destroy-completions-box) (define/private (destroy-completions-box)
@ -2482,7 +2480,7 @@ designates the character that triggers autocompletion
get-current-selection ; -> string get-current-selection ; -> string
narrow ; char -> boolean narrow ; char -> boolean
widen ; -> boolean widen ; -> boolean
)) empty?)) ; -> boolean
(define hidden-completions-text "⋮") (define hidden-completions-text "⋮")
@ -2501,6 +2499,8 @@ designates the character that triggers autocompletion
editor ; editor<%> the owner of this completion box editor ; editor<%> the owner of this completion box
) )
(define/public (empty?) (send completions empty?))
(define/private (compute-geometry) (define/private (compute-geometry)
(define vec #f) (define vec #f)
@ -2534,33 +2534,40 @@ designates the character that triggers autocompletion
(values 10 10)))) (values 10 10))))
(let* ([num-completions (send completions get-length)] (let* ([num-completions (send completions get-length)]
[shown-completions (send completions get-visible-completions)]) [shown-completions (send completions get-visible-completions)])
(define-values (w h) (define-values (w h)
(let ([dc (send editor get-dc)]) (let ([dc (send editor get-dc)])
(let loop ([pc shown-completions] (cond
[w 0] [(zero? num-completions)
[h 0] (let-values ([(tw th _1 _2) (send dc get-text-extent (string-constant no-completions)
[coord-map '()] (get-mt-font dc))])
[n 0]) (values (+ menu-padding-x tw menu-padding-x)
(cond (+ menu-padding-y th menu-padding-y)))]
[(null? pc) [else
(let-values ([(hidden?) (send completions items-are-hidden?)] (let loop ([pc shown-completions]
[(tw th _1 _2) (send dc get-text-extent hidden-completions-text)]) [w 0]
(let ([w (if hidden? (max tw w) w)] [h 0]
[h (if hidden? (+ th h) h)]) [coord-map '()]
(initialize-mouse-offset-map! coord-map) [n 0])
(let ([offset-h menu-padding-y] (cond
[offset-w (* menu-padding-x 2)]) [(null? pc)
(values (+ offset-w w) (let-values ([(hidden?) (send completions items-are-hidden?)]
(+ offset-h h)))))] [(tw th _1 _2) (send dc get-text-extent hidden-completions-text)])
[else (let ([w (if hidden? (max tw w) w)]
(let ([c (car pc)]) [h (if hidden? (+ th h) h)])
(let-values ([(tw th _1 _2) (send dc get-text-extent c)]) (initialize-mouse-offset-map! coord-map)
(loop (cdr pc) (let ([offset-h menu-padding-y]
(max tw w) [offset-w (* menu-padding-x 2)])
(+ th h) (values (+ offset-w w)
(cons (list (inexact->exact h) (inexact->exact (+ h th)) n) coord-map) (+ offset-h h)))))]
(add1 n))))])))) [else
(let ([c (car pc)])
(let-values ([(tw th _1 _2) (send dc get-text-extent c)])
(loop (cdr pc)
(max tw w)
(+ th h)
(cons (list (inexact->exact h) (inexact->exact (+ h th)) n) coord-map)
(add1 n))))]))])))
(let ([final-x (cond (let ([final-x (cond
[(< (+ menu-x w) editor-width) [(< (+ menu-x w) editor-width)
@ -2587,27 +2594,44 @@ designates the character that triggers autocompletion
(send dc set-brush (send editor get-autocomplete-background-color) 'solid) (send dc set-brush (send editor get-autocomplete-background-color) 'solid)
(let-values ([(mx my tw th) (get-menu-coordinates)]) (let-values ([(mx my tw th) (get-menu-coordinates)])
(send dc draw-rectangle (+ mx dx) (+ my dy) tw th) (send dc draw-rectangle (+ mx dx) (+ my dy) tw th)
(let loop ([item-number 0] [y my] [pc (send completions get-visible-completions)]) (cond
(cond [(send completions empty?)
[(null? pc) (let ([font (send dc get-font)])
(when (send completions items-are-hidden?) (send dc set-font (get-mt-font dc))
(let-values ([(hw _1 _2 _3) (send dc get-text-extent hidden-completions-text)]) (send dc draw-text (string-constant no-completions) (+ mx dx menu-padding-x) (+ menu-padding-y my dy))
(send dc draw-text (send dc set-font font))]
hidden-completions-text [else
(+ mx dx (- (/ tw 2) (/ hw 2))) (let loop ([item-number 0] [y my] [pc (send completions get-visible-completions)])
(+ menu-padding-y y dy))))] (cond
[else [(null? pc)
(let ([c (car pc)]) (when (send completions items-are-hidden?)
(let-values ([(w h d a) (send dc get-text-extent c)]) (let-values ([(hw _1 _2 _3) (send dc get-text-extent hidden-completions-text)])
(when (= item-number highlighted-menu-item) (send dc draw-text
(send dc set-pen "black" 1 'transparent) hidden-completions-text
(send dc set-brush (send editor get-autocomplete-selected-color) 'solid) (+ mx dx (- (/ tw 2) (/ hw 2)))
(send dc draw-rectangle (+ mx dx 1) (+ dy y menu-padding-y 1) (- tw 2) (- h 1))) (+ menu-padding-y y dy))))]
(send dc draw-text c (+ mx dx menu-padding-x) (+ menu-padding-y y dy)) [else
(loop (add1 item-number) (+ y h) (cdr pc))))]))) (let ([c (car pc)])
(let-values ([(w h d a) (send dc get-text-extent c)])
(when (= item-number highlighted-menu-item)
(send dc set-pen "black" 1 'transparent)
(send dc set-brush (send editor get-autocomplete-selected-color) 'solid)
(send dc draw-rectangle (+ mx dx 1) (+ dy y menu-padding-y 1) (- tw 2) (- h 1)))
(send dc draw-text c (+ mx dx menu-padding-x) (+ menu-padding-y y dy))
(loop (add1 item-number) (+ y h) (cdr pc))))]))]))
(send dc set-pen old-pen) (send dc set-pen old-pen)
(send dc set-brush old-brush))) (send dc set-brush old-brush)))
(define/private (get-mt-font dc)
(let ([font (send dc get-font)])
(send the-font-list find-or-create-font
(send font get-point-size)
(send font get-family)
'italic
(send font get-weight)
(send font get-underlined)
(send font get-smoothing))))
;; redraw : -> void ;; redraw : -> void
;; tells the parent to refresh enough of itself to redraw this menu ;; tells the parent to refresh enough of itself to redraw this menu
(define/public (redraw) (define/public (redraw)

View File

@ -641,6 +641,7 @@ please adhere to these guidelines:
(replace-and-find-again-menu-item "Replace && Find Again") (replace-and-find-again-menu-item "Replace && Find Again")
(complete-word "Complete Word") ; the complete word menu item in the edit menu (complete-word "Complete Word") ; the complete word menu item in the edit menu
(no-completions "... no completions available") ; shows up in the completions menu when there are no completions (in italics)
(preferences-info "Configure your preferences") (preferences-info "Configure your preferences")
(preferences-menu-item "Preferences...") (preferences-menu-item "Preferences...")