diff --git a/sloth/editor.scm b/sloth/editor.scm index 78d66ae..2c13b58 100644 --- a/sloth/editor.scm +++ b/sloth/editor.scm @@ -99,12 +99,22 @@ (string-take s k) (string-drop s (1+ k)))) +;;; merges k and k+1 +(define (merge-lines buffer k) + (append (list-head buffer k) + (list + (string-append (list-ref buffer k) + (list-ref buffer (1+ k)))) + (list-tail buffer (+ k 2)))) + (define (backward-delete-char state) (define buf (buffer state)) (define x (curx state)) (define y (cury state)) - (list-set! buf y - (string-delete-kth (list-ref buf y) (1- x))) + (if (> x 0) + (list-set! buf y + (string-delete-kth (list-ref buf y) (1- x))) + (set! (buffer state) (merge-lines buf (1- y)))) (move-cursor state #:x -1 #:relative? #t)) (define (delete-char state)