Skip to content

Commit

Permalink
fixes for when the colorer is off
Browse files Browse the repository at this point in the history
  • Loading branch information
rfindler committed Mar 6, 2024
1 parent 2f552b6 commit d0fefd8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
13 changes: 9 additions & 4 deletions gui-lib/framework/private/racket.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -1476,9 +1476,11 @@
(define open-len (if (string? open-brace) (string-length open-brace) 1))
(send text begin-edit-sequence #t #f)
(send text insert open-brace selection-start)
(define tok-type (send text classify-position selection-start))
(define tok-type (if (send text is-stopped?)
#f
(send text classify-position selection-start)))
(when (or (not checkp)
(and (symbol? checkp) (eq? checkp tok-type))
(and (symbol? checkp) (equal? checkp tok-type))
(and (procedure? checkp) (checkp tok-type)))
(define hash-before? ; tweak to detect and correctly close block comments #| ... |#
; Notice: This is racket-specific and despite the name of the file we should instead rely
Expand Down Expand Up @@ -1507,8 +1509,11 @@
(= startpos (send text get-end-position)))
(send text insert open-brace startpos (add1 startpos))
(send text insert open-brace))]

[else ; automatic-parens is enabled
; from here automatic-parens is enabled
[(send text is-stopped?)
;; when the colorer is stopped we just blindly insert both
(insert-brace-pair text open-brace close-brace)]
[else
(define c (immediately-following-cursor text))
(define cur-token
(send text classify-position (send text get-start-position)))
Expand Down
40 changes: 33 additions & 7 deletions gui-test/framework/tests/racket.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,15 @@
;; testing inserting parens and the automatic-parens prefs
;;

(define (type-something to-type [control-down #f])
(define (type-something to-type
#:control-down [control-down #f]
#:stop-colorer? [stop-colorer? #f])
(define f (new frame:basic% [label ""]))
(define t (new racket:text%))
(define ec (new canvas:basic%
[parent (send f get-area-container)]
[editor t]))
(when stop-colorer? (send t stop-colorer))
(send t on-char (new key-event% [key-code to-type] [control-down control-down]))
(send t get-text))

Expand All @@ -235,25 +238,39 @@
(check-equal? (type-something #\() "(")
(check-equal? (type-something #\[) "[")
(check-equal? (type-something #\") "\"")
(check-equal? (type-something #\( #:stop-colorer? #t) "(")
(check-equal? (type-something #\[ #:stop-colorer? #t) "[")
(check-equal? (type-something #\" #:stop-colorer? #t) "\"")

(preferences:set 'framework:automatic-parens #t)
(check-equal? (type-something #\() "()")
(check-equal? (type-something #\[) "[]")
(check-equal? (type-something #\") "\"\"")
(check-equal? (type-something #\( #:stop-colorer? #t) "()")
(check-equal? (type-something #\[ #:stop-colorer? #t) "[]")
(check-equal? (type-something #\" #:stop-colorer? #t) "\"\"")

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

(preferences:set 'framework:automatic-parens #f)
(check-equal? (type-something #\() "(")
(check-equal? (type-something #\[) "(")
(check-equal? (type-something #\[ #t) "[")
(check-equal? (type-something #\[ #:control-down #t) "[")
(check-equal? (type-something #\") "\"")
(check-equal? (type-something #\( #:stop-colorer? #t) "(")
(check-equal? (type-something #\[ #:stop-colorer? #t) "[") ;; if the colorer is off, no auto parens
(check-equal? (type-something #\[ #:stop-colorer? #t #:control-down #t) "[")
(check-equal? (type-something #\" #:stop-colorer? #t) "\"")
(preferences:set 'framework:automatic-parens #t)
(check-equal? (type-something #\() "()")
(check-equal? (type-something #\[) "()")
(check-equal? (type-something #\[ #t) "[]")
(check-equal? (type-something #\[ #:control-down #t) "[]")
(check-equal? (type-something #\") "\"\"")
(check-equal? (type-something #\( #:stop-colorer? #t) "()")
(check-equal? (type-something #\[ #:stop-colorer? #t) "[]") ;; if the colorer is off, no auto parens
(check-equal? (type-something #\[ #:stop-colorer? #t #:control-down #t) "[]")
(check-equal? (type-something #\" #:stop-colorer? #t) "\"\"")

(preferences:set 'framework:fixup-parens #t)
(preferences:set 'framework:fixup-open-parens #f)
Expand All @@ -262,10 +279,13 @@
(check-equal? (type-something #\() "(")
(check-equal? (type-something #\[) "[")
(check-equal? (type-something #\") "\"")
(check-equal? (type-something #\( #:stop-colorer? #t) "(")
(check-equal? (type-something #\[ #:stop-colorer? #t) "[")
(check-equal? (type-something #\" #:stop-colorer? #t) "\"")
(preferences:set 'framework:automatic-parens #t)
(check-equal? (type-something #\() "()")
(check-equal? (type-something #\[) "[]")
(check-equal? (type-something #\") "\"\"")
(check-equal? (type-something #\( #:stop-colorer? #t) "()")
(check-equal? (type-something #\[ #:stop-colorer? #t) "[]")
(check-equal? (type-something #\" #:stop-colorer? #t) "\"\"")

(preferences:set 'framework:fixup-parens #t)
(preferences:set 'framework:fixup-open-parens #t)
Expand All @@ -274,10 +294,16 @@
(check-equal? (type-something #\() "(")
(check-equal? (type-something #\[) "(")
(check-equal? (type-something #\") "\"")
(check-equal? (type-something #\( #:stop-colorer? #t) "(")
(check-equal? (type-something #\[ #:stop-colorer? #t) "[") ;; if the colorer is off, no auto parens
(check-equal? (type-something #\" #:stop-colorer? #t) "\"")
(preferences:set 'framework:automatic-parens #t)
(check-equal? (type-something #\() "()")
(check-equal? (type-something #\[) "()")
(check-equal? (type-something #\") "\"\""))
(check-equal? (type-something #\") "\"\"")
(check-equal? (type-something #\( #:stop-colorer? #t) "()")
(check-equal? (type-something #\[ #:stop-colorer? #t) "[]") ;; if the colorer is off, no auto parens
(check-equal? (type-something #\" #:stop-colorer? #t) "\"\""))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down

0 comments on commit d0fefd8

Please sign in to comment.