open-input-text-editor: beef up the protection that the lock-while-reading? argument provides

This commit is contained in:
Robby Findler 2010-12-14 10:28:05 -06:00
parent 5adaedae8e
commit 4881bc33f4
2 changed files with 21 additions and 8 deletions

View File

@ -106,7 +106,9 @@
(open-input-string (send text get-text start end) port-name) (open-input-string (send text get-text start end) port-name)
;; It's all text, so the reading process is simple: ;; It's all text, so the reading process is simple:
(let ([start start]) (let ([start start])
(when lock-while-reading? (send text lock #t)) (when lock-while-reading?
(send text begin-edit-sequence)
(send text lock #t))
(let-values ([(pipe-r pipe-w) (make-pipe)]) (let-values ([(pipe-r pipe-w) (make-pipe)])
(make-input-port/read-to-peek (make-input-port/read-to-peek
port-name port-name
@ -119,7 +121,8 @@
(close-output-port pipe-w) (close-output-port pipe-w)
(when lock-while-reading? (when lock-while-reading?
(set! lock-while-reading? #f) (set! lock-while-reading? #f)
(send text lock #f)) (send text lock #f)
(send text end-edit-sequence))
eof) eof)
(begin (begin
(write-string (send text get-text start (+ start n)) pipe-w) (write-string (send text get-text start (+ start n)) pipe-w)
@ -128,7 +131,8 @@
(when lock-while-reading? (when lock-while-reading?
(when (eof-object? ans) (when (eof-object? ans)
(set! lock-while-reading? #f) (set! lock-while-reading? #f)
(send text lock #f))) (send text lock #f)
(send text edit-edit-sequence)))
ans)))) ans))))
v))) v)))
(lambda (s skip general-peek) (lambda (s skip general-peek)
@ -198,7 +202,8 @@
(when (eof-object? res) (when (eof-object? res)
(when lock-while-reading? (when lock-while-reading?
(set! lock-while-reading? #f) (set! lock-while-reading? #f)
(send text lock #f))) (send text lock #f)
(send text end-edit-sequence)))
res)) res))
(lambda (s skip general-peek) (lambda (s skip general-peek)
(let ([v (peek-bytes-avail!* s skip #f pipe-r)]) (let ([v (peek-bytes-avail!* s skip #f pipe-r)])
@ -206,7 +211,9 @@
(general-peek s skip) (general-peek s skip)
v))) v)))
close)]) close)])
(when lock-while-reading? (send text lock #t)) (when lock-while-reading?
(send text begin-edit-sequencce)
(send text lock #t))
(if (is-a? snip wx:string-snip%) (if (is-a? snip wx:string-snip%)
;; Special handling for initial snip string in ;; Special handling for initial snip string in
;; case it starts too early: ;; case it starts too early:

View File

@ -254,9 +254,15 @@ The result port must not be used if @racket[text-editor] changes in any
@method[text% get-revision-number] method can be used to detect any of these changes. @method[text% get-revision-number] method can be used to detect any of these changes.
To help guard against such uses, if @racket[lock-while-reading?] argument is To help guard against such uses, if @racket[lock-while-reading?] argument is
a true value, then @racket[open-input-text-editor] will lock the @racket[text-editor] a true value, then @racket[open-input-text-editor] will
before it returns and unlock it after it is safe to use the above methods. (In some @method[editor<%> lock] the @racket[text-editor] and call
cases, it will not lock the editor at all, if using those methods are always safe.) @method[editor<%> begin-edit-sequence]
before it returns and un@method[editor<%> lock] it and
call @method[editor<%> end-edit-sequence]
after it is safe to use the above methods. (In some
cases, it will not @method[editor<%> lock] the editor
or put it in an edit sequence at all,
if using those methods are always safe.)
} }