change backspace in overwrite mode to be more what one

might expect it to be
This commit is contained in:
Robby Findler 2015-02-12 15:30:45 -06:00
parent 4140c530d6
commit cf6a3d6ecb
2 changed files with 35 additions and 1 deletions

View File

@ -612,7 +612,16 @@
(insert ch startpos (add1 startpos))
(insert ch)))])
(case code
[(#\backspace) (delete)]
[(#\backspace)
(cond
[(and overwrite-mode?
(= endpos startpos)
(not (zero? startpos)))
(begin-edit-sequence)
(insert #\space (- startpos 1) startpos)
(set-position (- startpos 1) (- startpos 1))
(end-edit-sequence)]
[else (delete)])]
[(#\rubout)
(if (= endpos startpos)
(when (endpos . < . len)

View File

@ -1561,6 +1561,31 @@
(send t1 insert "Hello\tWorld")
(send t1 get-extent (box 0) (box 0)))
;; ----------------------------------------
;; Overwrite mode
(let ([t (new text%)])
(send t set-admin (new test-editor-admin%))
(send t insert "abcdef")
(send t set-position 3 3)
(define (type c) (send t on-default-char (new key-event% [key-code c])))
(send t set-overwrite-mode #t)
(type #\z)
(expect (send t get-start-position) 4)
(expect (send t get-text) "abczef")
(type #\backspace)
(expect (send t get-start-position) 3)
(expect (send t get-text) "abc ef")
(send t set-position 1)
(type #\backspace)
(expect (send t get-start-position) 0)
(expect (send t get-text) " bc ef")
(type #\backspace)
(expect (send t get-start-position) 0)
(expect (send t get-text) " bc ef"))
;; ----------------------------------------
;; Identity and contracts