Skip to content

Commit addb2c9

Browse files
committed
Try to avoid a possible error in the normalize-paste code
judging from a runtime error I saw in DrRacket, it seems likely that this code causes the next/prev links to break and then things go wrong. I can't seem to make a test case that causes the problem, but if that is the problem, then this should fix it (as we now postpone modifications to the editor until after we know what all of them are instead of interleaving the changes to the buffer with a traversal that finds the changes to make)
1 parent ac20e5f commit addb2c9

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

gui-lib/framework/private/text-normalize-paste.rkt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
(define len (list-ref insertion 1))
9292
(split-snip start)
9393
(split-snip (+ start len))
94+
(define changes-to-make '())
9495
(let loop ([snip (find-snip (+ start len) 'before-or-none)])
9596
(when snip
9697
(define prev-snip (send snip previous))
@@ -105,7 +106,11 @@
105106
(unless (ask-normalize?) (abort)))
106107
(define snip-pos (get-snip-position snip))
107108
(delete snip-pos (+ snip-pos (string-length old)))
108-
(insert new snip-pos snip-pos #f)))
109-
(loop prev-snip)))))))
110-
109+
(set! changes-to-make
110+
(cons (λ () (insert new snip-pos snip-pos #f))
111+
changes-to-make))))
112+
(loop prev-snip))))
113+
(for ([change (in-list changes-to-make)])
114+
(change)))))
115+
111116
(super-new))))

gui-test/framework/tests/text.rkt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,32 @@
265265
(preferences:set 'framework:do-paste-normalization #t)
266266
(define t (new (text:normalize-paste-mixin text:basic%)))
267267
(send t as-a-paste (λ () (send t insert "x² x²\nx² x²\nx² x²\nx² x²\n")))
268-
(check-equal? (send t get-text) "x2 x2\nx2 x2\nx2 x2\nx2 x2\n")))
268+
(check-equal? (send t get-text) "x2 x2\nx2 x2\nx2 x2\nx2 x2\n"))
269+
270+
(let ()
271+
(preferences:set 'framework:do-paste-normalization #t)
272+
(define t (new (text:normalize-paste-mixin text:basic%)))
273+
(send t as-a-paste (λ ()
274+
(send t insert "x²\n")
275+
(send t insert "x²\n")))
276+
(check-equal? (send t get-text) "x2\nx2\n"))
277+
278+
(let ()
279+
(preferences:set 'framework:do-paste-normalization #t)
280+
(define t (new (text:normalize-paste-mixin text:basic%)))
281+
(send t as-a-paste (λ ()
282+
(send t insert "x²\n")
283+
(send t insert "x³\n")))
284+
(check-equal? (send t get-text) "x2\nx3\n"))
285+
286+
(let ()
287+
(preferences:set 'framework:do-paste-normalization #t)
288+
(define t (new (text:normalize-paste-mixin text:basic%)))
289+
(send t as-a-paste (λ ()
290+
(send t insert "x²\n")
291+
(send t insert "x³\n")
292+
(send t insert "x³\n")))
293+
(check-equal? (send t get-text) "x2\nx3\nx3\n")))
269294

270295
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
271296
;;

0 commit comments

Comments
 (0)