]> git.mdlowis.com Git - projs/tide.git/commitdiff
tweaked cursor movement
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 27 Oct 2019 20:13:59 +0000 (16:13 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 27 Oct 2019 20:13:59 +0000 (16:13 -0400)
TODO.md
src/lib/buf.c
tests/lib/buf.c

diff --git a/TODO.md b/TODO.md
index adcead51065395c8e3b9b1cfaabf20e50d82dab9..e5534d268c3b3db21e7597979832aab6a9edacb7 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -9,7 +9,6 @@
 * tide: move looping of cursor movements into selmoveby
 * all: eliminate multiple return statements and other lint
 * tide: byrune, byword, byline functions should be hidden in buf.c
-* tide: column tracking should be hidden in buf.c
 * tide: buf_findstr has an infinite loop condition
 * tide: refactor undo/redo api in view.c
 
index 055adb8cc382c553f0fc4485ebb9696b02ee735e..a95644199f72f6d102c372cead14f50348bf9c17 100644 (file)
@@ -849,7 +849,7 @@ void buf_selmove(Buf* buf, bool extsel, int move, int bything)
     if (buf_selsz(buf) && !extsel)
     {
         buf_selclr(buf, move);
-        if (bything == BY_LINE && move < 0)
+        if (bything == BY_LINE)
         {
             buf->selection.end = buf_moveby(buf, bything, buf->selection.end, move);
         }
index bce8927710a8a311f146806859c5fed06b48c0fe..98a1402461496110487bfdd66afeaa5b43a55fdd 100644 (file)
@@ -767,4 +767,24 @@ TEST_SUITE(BufferTests)
         CHECK(5 == TestBuf.selection.end);
         CHECK(10 == TestBuf.selection.col);
     }
+
+    TEST(buf_selmove should clear selection and move cursor up one line)
+    {
+        set_buffer_text("aa\nbb\ncc\n");
+        TestBuf.selection = (Sel){ .beg = 4, .end = 5, .col = 1 };
+        buf_selmove(&TestBuf, false, UP, BY_LINE);
+        CHECK(1 == TestBuf.selection.beg);
+        CHECK(1 == TestBuf.selection.end);
+        CHECK(1 == TestBuf.selection.col);
+    }
+
+    TEST(buf_selmove should clear selection and move cursor down one line)
+    {
+        set_buffer_text("aa\nbb\ncc\n");
+        TestBuf.selection = (Sel){ .beg = 4, .end = 5, .col = 2 };
+        buf_selmove(&TestBuf, false, DOWN, BY_LINE);
+        CHECK(8 == TestBuf.selection.beg);
+        CHECK(8 == TestBuf.selection.end);
+        CHECK(2 == TestBuf.selection.col);
+    }
 }