From 55a251642ff83fab36d33228e90095bd641ed0dd Mon Sep 17 00:00:00 2001 From: Skylar Hill Date: Wed, 8 Nov 2023 11:58:12 -0600 Subject: [PATCH] Allow merging lines by backspacing at the beginning of a line --- sloth/editor.scm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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)