Possible fix for error raised by build-rectangle

When switching tabs while an on-reflow initiated callback
might still be running can lead to bogus information
coming back from position-locations, as the editor loses
its admin.

So, we just give up recomputing the rectangles when the
admin is gone and, for now, expect that there will be
another on-reflow call when the admin comes back that'll
restart the process (not sure that this is guaranteed tho)

original commit: 52d0b7e352a493e127e0d7cd780a34938dddea08
This commit is contained in:
Robby Findler 2012-11-28 09:44:08 -06:00
parent f0e71cebf5
commit d54e68a2e7

View File

@ -122,48 +122,52 @@
(define recompute-callback-running? #f) (define recompute-callback-running? #f)
(define/private (run-recompute-range-rectangles) (define/private (run-recompute-range-rectangles)
(define done-time (+ (current-inexact-milliseconds) 20)) (when (get-admin)
(define did-something? #f) ;; when there is no admin, then the position-location information
(let loop ([left #f] ;; is bogus, so we just give up trying to recompute this information
[top #f]
[right #f] (define done-time (+ (current-inexact-milliseconds) 20))
[bottom #f]) (define did-something? #f)
(cond (let loop ([left #f]
[(and did-something? ((current-inexact-milliseconds) . >= . done-time)) [top #f]
(final-invalidate left top right bottom) [right #f]
(queue-callback [bottom #f])
(λ () (run-recompute-range-rectangles)) (cond
#f)] [(and did-something? ((current-inexact-milliseconds) . >= . done-time))
[(null? pending-ranges) (final-invalidate left top right bottom)
(final-invalidate left top right bottom) (queue-callback
(set! recompute-callback-running? #f)] (λ () (run-recompute-range-rectangles))
[else #f)]
(set! did-something? #t) [(null? pending-ranges)
(define a-range (car pending-ranges)) (final-invalidate left top right bottom)
(set! pending-ranges (cdr pending-ranges)) (set! recompute-callback-running? #f)]
(define old-rectangles (range-rectangles a-range)) [else
(cond (set! did-something? #t)
[old-rectangles (define a-range (car pending-ranges))
(define new-rectangles (compute-rectangles a-range)) (set! pending-ranges (cdr pending-ranges))
(cond (define old-rectangles (range-rectangles a-range))
[(equal? new-rectangles old-rectangles) (cond
(loop left top right bottom)] [old-rectangles
[else (define new-rectangles (compute-rectangles a-range))
(define-values (new-left new-top new-right new-bottom) (cond
(for/fold ([left left] [top top] [right right] [bottom bottom]) [(equal? new-rectangles old-rectangles)
([r (in-list new-rectangles)]) (loop left top right bottom)]
(join-rectangles left top right bottom r))) [else
(define-values (both-left both-top both-right both-bottom) (define-values (new-left new-top new-right new-bottom)
(for/fold ([left new-left] [top new-top] [right new-right] [bottom new-bottom]) (for/fold ([left left] [top top] [right right] [bottom bottom])
([r (in-list old-rectangles)]) ([r (in-list new-rectangles)])
(join-rectangles left top right bottom r))) (join-rectangles left top right bottom r)))
(set-range-rectangles! a-range new-rectangles) (define-values (both-left both-top both-right both-bottom)
(loop both-left both-top both-right both-bottom)])] (for/fold ([left new-left] [top new-top] [right new-right] [bottom new-bottom])
[else ([r (in-list old-rectangles)])
;; when old-rectangles is #f, that means that this (join-rectangles left top right bottom r)))
;; range has been removed from the ranges-deq, so (set-range-rectangles! a-range new-rectangles)
;; can just skip over it here. (loop both-left both-top both-right both-bottom)])]
(loop left top right bottom)])]))) [else
;; when old-rectangles is #f, that means that this
;; range has been removed from the ranges-deq, so
;; can just skip over it here.
(loop left top right bottom)])]))))
(define/private (join-rectangles left top right bottom r) (define/private (join-rectangles left top right bottom r)
(define this-left (define this-left