From d93d71e322d2c70666be8b3de67d3536371ba4b4 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 27 Oct 2019 16:13:59 -0400 Subject: [PATCH] tweaked cursor movement --- TODO.md | 1 - src/lib/buf.c | 2 +- tests/lib/buf.c | 20 ++++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index adcead5..e5534d2 100644 --- 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 diff --git a/src/lib/buf.c b/src/lib/buf.c index 055adb8..a956441 100644 --- a/src/lib/buf.c +++ b/src/lib/buf.c @@ -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); } diff --git a/tests/lib/buf.c b/tests/lib/buf.c index bce8927..98a1402 100644 --- a/tests/lib/buf.c +++ b/tests/lib/buf.c @@ -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); + } } -- 2.51.0