]> git.mdlowis.com Git - projs/tide.git/commitdiff
Fixed infinite loop in indent/unindent code
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 22 Dec 2016 21:51:33 +0000 (16:51 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 22 Dec 2016 21:51:33 +0000 (16:51 -0500)
TODO.md
libedit/view.c
tests/xedit.c

diff --git a/TODO.md b/TODO.md
index 37149b6227bb55c6d5be47c6846b3ab3db929964..f277b74a9d8711778152b071c491007de22df364 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -3,7 +3,6 @@
 Up Next:
 
 * Tag line count should account for wrapped lines
-* Indent/Unindent on first line of buffer causes infinite loop
 * block selection should handle brace-balancing
 * context sensitive selection of words, commands, line numbers, or filenames.
 * ctrl+f should move the pointer to the match
index f25822dcb9ed635c86881f6285af1109014f3b1c..3740a416050439377dd806cfc3a75a71f113732d 100644 (file)
@@ -588,7 +588,8 @@ void view_indent(View* view, int dir) {
     view->selection.end = buf_eol(buf, view->selection.end);
     unsigned off = buf_bol(buf, view->selection.end);
     if (num_selected(view->selection) == 0) return;
-    while (off >= view->selection.beg) {
+    
+    do {
         if (dir == RIGHT) {
             buf_insert(buf, true, off, '\t');
             view->selection.end += indoff;
@@ -608,5 +609,6 @@ void view_indent(View* view, int dir) {
             }
         }
         off = buf_byline(buf, off, UP);
-    }
+        
+   } while (off && off >= view->selection.beg);
 }
index c4d76d32c46aafbe07693449c198dde5dfa8f388..6e187535cccaca35ff90b1b28894f7c523452fea 100644 (file)
@@ -483,12 +483,12 @@ TEST_SUITE(XeditTests) {
         CHECK(getsel(EDIT)->end == 0);
     }
     
-    //TEST(ctrl+[ should do nothing on empty buffer) {
-    //    setup_view(EDIT, "a", CRLF, 0);
-    //    send_keys(ModCtrl, '[');
-    //    CHECK(getsel(EDIT)->beg == 0);
-    //    CHECK(getsel(EDIT)->end == 0);
-    //}
+    TEST(ctrl+[ should do nothing at beginning of buffer) {
+        setup_view(EDIT, "a", CRLF, 0);
+        send_keys(ModCtrl, '[');
+        CHECK(getsel(EDIT)->beg == 0);
+        CHECK(getsel(EDIT)->end == 1);
+    }
     
     TEST(ctrl+] should do nothing on empty buffer) {
         setup_view(EDIT, "", CRLF, 0);
@@ -497,12 +497,13 @@ TEST_SUITE(XeditTests) {
         CHECK(getsel(EDIT)->end == 0);
     }
     
-    //TEST(ctrl+] should indent the current line) {
-    //    setup_view(EDIT, "a", CRLF, 0);
-    //    send_keys(ModCtrl, ']');
-    //    CHECK(getsel(EDIT)->beg == 0);
-    //    CHECK(getsel(EDIT)->end == 0);
-    //}
+    TEST(ctrl+] should indent the first line) {
+        setup_view(EDIT, "a", CRLF, 0);
+        send_keys(ModCtrl, ']');
+        CHECK(getsel(EDIT)->beg == 0);
+        CHECK(getsel(EDIT)->end == 5);
+        CHECK(verify_text(EDIT, "    a"));
+    }
     
     /* Key Handling - Special 
      *************************************************************************/