Skip to content

Commit

Permalink
fix editor crash
Browse files Browse the repository at this point in the history
  • Loading branch information
6cdh authored and jeapostrophe committed Jul 11, 2023
1 parent c97961b commit 45f5767
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions editor.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,32 @@
(class object%
(define core (new racket:text%))

;; workaround for sequence-contract-violation problem
(define/private (reload!)
(define new-core (new racket:text%))
(send new-core insert (send core get-text) 0)
(set! core new-core))

(define/private (set-core! new-core)
(set! core new-core))

;; insert str at start
(define/public (insert str start)
(send core insert str start))
(with-handlers ([exn?
(λ _
(reload!)
;; only retry once
(send core insert str start))])
(send core insert str start)))

;; replace text at (range start end) with str
(define/public (replace str start end)
(send core insert str start end))
(with-handlers ([exn?
(λ _
(reload!)
;; only retry once
(send core insert str start end))])
(send core insert str start end)))

(define/public (delete start end)
(send core delete start end))
Expand Down

0 comments on commit 45f5767

Please sign in to comment.