From 20ef7ed6f13711f3fd3eb8bcd637bca0a5cee758 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 26 Sep 2018 15:38:21 -0400 Subject: [PATCH] fixed logic for fixing user selection when whitespace is deleted --- lib/buf.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/buf.c b/lib/buf.c index c116177..e6d95d5 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -153,16 +153,15 @@ static void trim_whitespace(Buf* buf) { /* If we reached a newline, then delete whatever we have selected */ if (r == '\r' || r == '\n') { buf->selection.beg = buf_byrune(buf, buf->selection.beg, +1); + Sel del = buf->selection; + sel.beg -= (del.beg < sel.beg ? (min(del.end, sel.beg) - del.beg) : 0); + sel.end -= (del.beg < sel.end ? (min(del.end, sel.end) - del.beg) : 0); buf_del(buf); } /* if current char is not whitespace, then shrink the selection */ - if (r != ' ' && r != '\t') { + if (r != ' ' && r != '\t') buf->selection.beg = buf->selection.end; - } else { - if (buf->selection.end <= sel.beg) sel.beg--; - if (buf->selection.end <= sel.end) sel.end--; - } /* move to the next character */ prev = buf->selection.end; -- 2.49.0