From cf6a3d6ecbd28a9910714076a719dd0b77a44ce9 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Thu, 12 Feb 2015 15:30:45 -0600 Subject: [PATCH] change backspace in overwrite mode to be more what one might expect it to be --- gui-lib/mred/private/wxme/text.rkt | 11 ++++++++++- gui-test/tests/gracket/wxme.rkt | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/gui-lib/mred/private/wxme/text.rkt b/gui-lib/mred/private/wxme/text.rkt index fcc9c165..15040880 100644 --- a/gui-lib/mred/private/wxme/text.rkt +++ b/gui-lib/mred/private/wxme/text.rkt @@ -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) diff --git a/gui-test/tests/gracket/wxme.rkt b/gui-test/tests/gracket/wxme.rkt index 4666e063..37b384b8 100644 --- a/gui-test/tests/gracket/wxme.rkt +++ b/gui-test/tests/gracket/wxme.rkt @@ -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