Skip to content

Commit d0fefd8

Browse files
committed
fixes for when the colorer is off
closes racket/drracket#665
1 parent 2f552b6 commit d0fefd8

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

gui-lib/framework/private/racket.rkt

+9-4
Original file line numberDiff line numberDiff line change
@@ -1476,9 +1476,11 @@
14761476
(define open-len (if (string? open-brace) (string-length open-brace) 1))
14771477
(send text begin-edit-sequence #t #f)
14781478
(send text insert open-brace selection-start)
1479-
(define tok-type (send text classify-position selection-start))
1479+
(define tok-type (if (send text is-stopped?)
1480+
#f
1481+
(send text classify-position selection-start)))
14801482
(when (or (not checkp)
1481-
(and (symbol? checkp) (eq? checkp tok-type))
1483+
(and (symbol? checkp) (equal? checkp tok-type))
14821484
(and (procedure? checkp) (checkp tok-type)))
14831485
(define hash-before? ; tweak to detect and correctly close block comments #| ... |#
14841486
; Notice: This is racket-specific and despite the name of the file we should instead rely
@@ -1507,8 +1509,11 @@
15071509
(= startpos (send text get-end-position)))
15081510
(send text insert open-brace startpos (add1 startpos))
15091511
(send text insert open-brace))]
1510-
1511-
[else ; automatic-parens is enabled
1512+
; from here automatic-parens is enabled
1513+
[(send text is-stopped?)
1514+
;; when the colorer is stopped we just blindly insert both
1515+
(insert-brace-pair text open-brace close-brace)]
1516+
[else
15121517
(define c (immediately-following-cursor text))
15131518
(define cur-token
15141519
(send text classify-position (send text get-start-position)))

gui-test/framework/tests/racket.rkt

+33-7
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,15 @@
218218
;; testing inserting parens and the automatic-parens prefs
219219
;;
220220

221-
(define (type-something to-type [control-down #f])
221+
(define (type-something to-type
222+
#:control-down [control-down #f]
223+
#:stop-colorer? [stop-colorer? #f])
222224
(define f (new frame:basic% [label ""]))
223225
(define t (new racket:text%))
224226
(define ec (new canvas:basic%
225227
[parent (send f get-area-container)]
226228
[editor t]))
229+
(when stop-colorer? (send t stop-colorer))
227230
(send t on-char (new key-event% [key-code to-type] [control-down control-down]))
228231
(send t get-text))
229232

@@ -235,25 +238,39 @@
235238
(check-equal? (type-something #\() "(")
236239
(check-equal? (type-something #\[) "[")
237240
(check-equal? (type-something #\") "\"")
241+
(check-equal? (type-something #\( #:stop-colorer? #t) "(")
242+
(check-equal? (type-something #\[ #:stop-colorer? #t) "[")
243+
(check-equal? (type-something #\" #:stop-colorer? #t) "\"")
238244

239245
(preferences:set 'framework:automatic-parens #t)
240246
(check-equal? (type-something #\() "()")
241247
(check-equal? (type-something #\[) "[]")
242248
(check-equal? (type-something #\") "\"\"")
249+
(check-equal? (type-something #\( #:stop-colorer? #t) "()")
250+
(check-equal? (type-something #\[ #:stop-colorer? #t) "[]")
251+
(check-equal? (type-something #\" #:stop-colorer? #t) "\"\"")
243252

244253
(preferences:set 'framework:fixup-parens #f)
245254
(preferences:set 'framework:fixup-open-parens #t)
246255

247256
(preferences:set 'framework:automatic-parens #f)
248257
(check-equal? (type-something #\() "(")
249258
(check-equal? (type-something #\[) "(")
250-
(check-equal? (type-something #\[ #t) "[")
259+
(check-equal? (type-something #\[ #:control-down #t) "[")
251260
(check-equal? (type-something #\") "\"")
261+
(check-equal? (type-something #\( #:stop-colorer? #t) "(")
262+
(check-equal? (type-something #\[ #:stop-colorer? #t) "[") ;; if the colorer is off, no auto parens
263+
(check-equal? (type-something #\[ #:stop-colorer? #t #:control-down #t) "[")
264+
(check-equal? (type-something #\" #:stop-colorer? #t) "\"")
252265
(preferences:set 'framework:automatic-parens #t)
253266
(check-equal? (type-something #\() "()")
254267
(check-equal? (type-something #\[) "()")
255-
(check-equal? (type-something #\[ #t) "[]")
268+
(check-equal? (type-something #\[ #:control-down #t) "[]")
256269
(check-equal? (type-something #\") "\"\"")
270+
(check-equal? (type-something #\( #:stop-colorer? #t) "()")
271+
(check-equal? (type-something #\[ #:stop-colorer? #t) "[]") ;; if the colorer is off, no auto parens
272+
(check-equal? (type-something #\[ #:stop-colorer? #t #:control-down #t) "[]")
273+
(check-equal? (type-something #\" #:stop-colorer? #t) "\"\"")
257274

258275
(preferences:set 'framework:fixup-parens #t)
259276
(preferences:set 'framework:fixup-open-parens #f)
@@ -262,10 +279,13 @@
262279
(check-equal? (type-something #\() "(")
263280
(check-equal? (type-something #\[) "[")
264281
(check-equal? (type-something #\") "\"")
282+
(check-equal? (type-something #\( #:stop-colorer? #t) "(")
283+
(check-equal? (type-something #\[ #:stop-colorer? #t) "[")
284+
(check-equal? (type-something #\" #:stop-colorer? #t) "\"")
265285
(preferences:set 'framework:automatic-parens #t)
266-
(check-equal? (type-something #\() "()")
267-
(check-equal? (type-something #\[) "[]")
268-
(check-equal? (type-something #\") "\"\"")
286+
(check-equal? (type-something #\( #:stop-colorer? #t) "()")
287+
(check-equal? (type-something #\[ #:stop-colorer? #t) "[]")
288+
(check-equal? (type-something #\" #:stop-colorer? #t) "\"\"")
269289

270290
(preferences:set 'framework:fixup-parens #t)
271291
(preferences:set 'framework:fixup-open-parens #t)
@@ -274,10 +294,16 @@
274294
(check-equal? (type-something #\() "(")
275295
(check-equal? (type-something #\[) "(")
276296
(check-equal? (type-something #\") "\"")
297+
(check-equal? (type-something #\( #:stop-colorer? #t) "(")
298+
(check-equal? (type-something #\[ #:stop-colorer? #t) "[") ;; if the colorer is off, no auto parens
299+
(check-equal? (type-something #\" #:stop-colorer? #t) "\"")
277300
(preferences:set 'framework:automatic-parens #t)
278301
(check-equal? (type-something #\() "()")
279302
(check-equal? (type-something #\[) "()")
280-
(check-equal? (type-something #\") "\"\""))
303+
(check-equal? (type-something #\") "\"\"")
304+
(check-equal? (type-something #\( #:stop-colorer? #t) "()")
305+
(check-equal? (type-something #\[ #:stop-colorer? #t) "[]") ;; if the colorer is off, no auto parens
306+
(check-equal? (type-something #\" #:stop-colorer? #t) "\"\""))
281307

282308

283309
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

0 commit comments

Comments
 (0)