]> git.mdlowis.com Git - projs/tide.git/commitdiff
Tweaked trimming logic to trime withespace even if its only one char worth.
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 22 May 2017 13:02:50 +0000 (09:02 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 22 May 2017 13:02:50 +0000 (09:02 -0400)
xedit.c

diff --git a/xedit.c b/xedit.c
index 996b3aebf1b969ff3be788ccdfb41000202f0e80..dfaf74052eb6db210bf2a1a3abffcc74be1f664f 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -130,8 +130,9 @@ static void save(void) {
     Buf* buf = win_buf(EDIT);
     if (TrimOnSave && buf_end(buf) > 0) {
         View* view = win_view(EDIT);
-        unsigned off = 0;
-        while (off < buf_end(buf)-1) {
+        unsigned off = 0, prev = 1;
+        /* loop through the buffer till we hit the end or we stop advancing */
+        while (off < buf_end(buf) && prev != off) {
             off = buf_eol(buf, off);
             Rune r = buf_get(buf, off-1);
             for (; (r == ' ' || r == '\t'); r = buf_get(buf, off-1)) {
@@ -141,7 +142,9 @@ static void save(void) {
                 }
                 off = buf_delete(buf, off-1, off);
             }
-            off = buf_byline(buf, off, +1);
+            /* make sure we keep advancing */
+            prev = off;
+            off  = buf_byline(buf, off, +1);
         }
     }
     buf_save(buf);