Only highlight text, not empty space at the end of lines.

To play nicer with pop-up menus.
This commit is contained in:
Vincent St-Amour 2012-07-02 17:36:34 -04:00
parent d48762fa1d
commit 8b64dc8aef

View File

@ -46,7 +46,8 @@
(mixin (text:basic<%> drracket:unit:definitions-text<%>) () (mixin (text:basic<%> drracket:unit:definitions-text<%>) ()
(inherit highlight-range unhighlight-range (inherit highlight-range unhighlight-range
set-clickback remove-clickback set-clickback remove-clickback
get-tab) get-tab get-canvas get-pos/text
position-line line-end-position)
(define highlights '()) (define highlights '())
(define color-table #f) (define color-table #f)
@ -64,10 +65,29 @@
(let ([color (if (= badness 0) (let ([color (if (= badness 0)
"lightgreen" "lightgreen"
(vector-ref color-table badness))]) (vector-ref color-table badness))])
(highlight-to-end-of-text start end color l))]))
;; highlight-range, for ranges that span multiple lines, highlights
;; to the end of the first n-1 lines. Since the space at end of lines
;; does not have editor positions, I can't figure out how to make the
;; popup menu appear there (I can only make it appear in places that
;; have positions). To work around that, we highlight only the code
;; proper, not the space at the end of lines. That way, everywhere in
;; the highlight has a position, and can spawn popup menus.
(define/private (highlight-to-end-of-text start end color l)
(define (highlight-part start end)
(highlight-range start end color #f 'high) (highlight-range start end color #f 'high)
(set-clickback start end (popup-callback l)) (set-clickback start end (popup-callback l))
;; record highlight to undo it later ;; record highlight to undo it later
(list start end color))])) (set! highlights (cons (list start end color) highlights)))
(let loop ([start start])
(define line (position-line start))
(define end-of-line (line-end-position line))
(cond [(>= end-of-line end)
(highlight-part start end)] ; done
[else
(highlight-part start end-of-line)
(loop (add1 end-of-line))])))
(define report-cache #f) (define report-cache #f)
(define/public (add-highlights #:use-cache? [use-cache? #f]) (define/public (add-highlights #:use-cache? [use-cache? #f])
@ -86,13 +106,7 @@
(apply max (cons 0 (map report-entry-badness report)))) (apply max (cons 0 (map report-entry-badness report))))
(unless (= max-badness 0) ; no missed opts, color table code would error (unless (= max-badness 0) ; no missed opts, color table code would error
(set! color-table (make-color-table max-badness))) (set! color-table (make-color-table max-badness)))
(define new-highlights (for ([r (in-list report)]) (highlight-entry r)))
(let loop ([report report])
(cond
[(null? report) highlights]
[else (cons (highlight-entry (car report))
(loop (cdr report)))])))
(set! highlights new-highlights))
(define/public (clear-highlights) (define/public (clear-highlights)
(for ([h (in-list highlights)]) (for ([h (in-list highlights)])