From 927289cd8e592009cfecd59ef3d4a02ee75f8868 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Tue, 30 Dec 2014 11:59:30 -0600 Subject: [PATCH] make the search/replace button actually finish all the internal work before returning from the button callback closes PR 14906 --- gui-doc/scribblings/framework/text.scrbl | 5 ++++ gui-lib/framework/private/frame.rkt | 25 +++++++++--------- gui-lib/framework/private/text.rkt | 32 +++++++++++++++++------- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/gui-doc/scribblings/framework/text.scrbl b/gui-doc/scribblings/framework/text.scrbl index c3bd0b4e..0090ca8d 100644 --- a/gui-doc/scribblings/framework/text.scrbl +++ b/gui-doc/scribblings/framework/text.scrbl @@ -528,6 +528,11 @@ tracked via the @method[text% after-set-position] method.) } + @defmethod[(finish-pending-search-work) void?]{ + Finishes any pending work in computing and + drawing the search bubbles. + } + @defmethod[(get-search-bubbles) (listof (list/c (cons/c number? number?) (or/c 'normal-search-color diff --git a/gui-lib/framework/private/frame.rkt b/gui-lib/framework/private/frame.rkt index 3ddcd797..dd95a73d 100644 --- a/gui-lib/framework/private/frame.rkt +++ b/gui-lib/framework/private/frame.rkt @@ -2469,18 +2469,19 @@ (unhide-search #f) (send find-edit search searching-direction #t)) - (define/public (search-replace) - (let ([text-to-search (get-text-to-search)]) - (when text-to-search - (let ([replacee-start (send text-to-search get-replace-search-hit)]) - (when replacee-start - (let ([replacee-end (+ replacee-start (send find-edit last-position))]) - (send text-to-search begin-edit-sequence) - (send text-to-search set-position replacee-end replacee-end) - (send text-to-search delete replacee-start replacee-end) - (copy-over replace-edit 0 (send replace-edit last-position) text-to-search replacee-start) - (search 'forward) - (send text-to-search end-edit-sequence))))))) + (define/public (search-replace) + (define text-to-search (get-text-to-search)) + (when text-to-search + (define replacee-start (send text-to-search get-replace-search-hit)) + (when replacee-start + (define replacee-end (+ replacee-start (send find-edit last-position))) + (send text-to-search begin-edit-sequence) + (send text-to-search set-position replacee-end replacee-end) + (send text-to-search delete replacee-start replacee-end) + (copy-over replace-edit 0 (send replace-edit last-position) text-to-search replacee-start) + (search 'forward) + (send text-to-search finish-pending-search-work) + (send text-to-search end-edit-sequence)))) (define/private (copy-over src-txt src-start src-end dest-txt dest-pos) (send src-txt split-snip src-start) diff --git a/gui-lib/framework/private/text.rkt b/gui-lib/framework/private/text.rkt index d4f67ab0..20e5c47a 100644 --- a/gui-lib/framework/private/text.rkt +++ b/gui-lib/framework/private/text.rkt @@ -1097,7 +1097,8 @@ set-searching-state set-search-anchor get-search-bubbles - get-search-hit-count)) + get-search-hit-count + finish-pending-search-work)) (define normal-search-color (send the-color-database find-color "plum")) (define dark-search-color (send the-color-database find-color "mediumorchid")) @@ -1343,14 +1344,27 @@ (queue-callback (λ () (run-search)) #f))) (define/private (run-search) - (define done? (coroutine-run search-coroutine (void))) - (cond - [done? - (set! search-coroutine #f)] - [else - (queue-callback - (λ () (run-search)) - #f)])) + ;; there may be a call to (finish-pending-search-work) with a run-search + ;; pending so we check to see if that happened and do no work in that case. + (when search-coroutine + (define done? (coroutine-run search-coroutine (void))) + (cond + [done? + (set! search-coroutine #f)] + [else + (queue-callback + (λ () (run-search)) + #f)]))) + + (define/public (finish-pending-search-work) + (when search-coroutine + (let loop () + (define done? (coroutine-run search-coroutine (void))) + (cond + [done? + (set! search-coroutine #f)] + [else + (loop)])))) (define/private (create-search-coroutine notify-frame?) (coroutine