From 3fc1bf7a77308fbf23242e243c97a492224b5845 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 22 Jun 2017 10:48:55 -0400 Subject: [PATCH] Fixed click handling for gutter and scroll region --- TODO.md | 3 ++- lib/win.c | 4 ++-- tests/lib/buf.c | 38 +++++++++++++++++++------------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/TODO.md b/TODO.md index 62d1e62..2af7910 100644 --- a/TODO.md +++ b/TODO.md @@ -2,6 +2,7 @@ Up Next: +* highlighting is broken for comments partially off screen (again) * implement transaction control in buf.c * highlight all matches of search term * highlight classes of identifiers @@ -11,7 +12,7 @@ Up Next: * move by words is inconsistent. Example: var infoId = 'readerinfo'+reader.id; * ignore the menu key or map it to control - + The Future: * Ctrl+/ shortcut to comment/uncomment based on syntax diff --git a/lib/win.c b/lib/win.c index 4d5baad..9aed482 100644 --- a/lib/win.c +++ b/lib/win.c @@ -354,9 +354,9 @@ static void onmousedrag(int state, int x, int y) { } static void onmousebtn(int btn, bool pressed, int x, int y) { - if (x < Regions[Focused].x) - x = Regions[Focused].x; WinRegion id = getregion(x, y); + if (id == FOCUSED && x < Regions[Focused].x) + x = Regions[Focused].x, id = getregion(x, y); size_t row = (y-Regions[id].y) / x11_font_height(Font); size_t col = (x-Regions[id].x) / x11_font_width(Font); diff --git a/tests/lib/buf.c b/tests/lib/buf.c index f9555ac..566cebd 100644 --- a/tests/lib/buf.c +++ b/tests/lib/buf.c @@ -20,13 +20,13 @@ static void set_buffer_text(char* str) { static bool buf_text_eq(char* str) { for (unsigned i = 0; i < buf_end(&TestBuf); i++) { - printf("'%c'", buf_get(&TestBuf, i)); + //printf("'%c'", buf_get(&TestBuf, i)); if ((Rune)*(str++) != buf_get(&TestBuf, i)) { - printf("\n"); + //printf("\n"); return false; } } - printf("\n"); + //printf("\n"); return true; } @@ -51,7 +51,7 @@ TEST_SUITE(BufferTests) { CHECK(buf.errfn == (void*)0x12345678); CHECK(buf.nlines == 0); } - + TEST(buf_init shoud free old buffer and reinitialize) { Buf buf = {0}; buf_init(&buf, onerror); @@ -72,7 +72,7 @@ TEST_SUITE(BufferTests) { CHECK(buf.errfn == (void*)0x12345678); CHECK(buf.nlines == 0); } - + /* Loading *************************************************************************/ TEST(buf_load should load a UTF-8 file from disk) { @@ -91,7 +91,7 @@ TEST_SUITE(BufferTests) { CHECK(TestBuf.nlines == 998); CHECK(!strcmp(TestBuf.path, "testdocs/lorem.txt")); } - + TEST(buf_load should load a non UTF-8 file from disk) { buf_init(&TestBuf, NULL); size_t pos = buf_load(&TestBuf, "testdocs/waf"); @@ -108,7 +108,7 @@ TEST_SUITE(BufferTests) { CHECK(TestBuf.nlines == 169); CHECK(!strcmp(TestBuf.path, "testdocs/waf")); } - + TEST(buf_load should load a file from disk and jump to a specific line) { buf_init(&TestBuf, NULL); size_t pos = buf_load(&TestBuf, "testdocs/lorem.txt:2"); @@ -125,7 +125,7 @@ TEST_SUITE(BufferTests) { CHECK(TestBuf.nlines == 998); CHECK(!strcmp(TestBuf.path, "testdocs/lorem.txt")); } - + TEST(buf_load should remove ./ from file path) { buf_init(&TestBuf, NULL); size_t pos = buf_load(&TestBuf, "./testdocs/lorem.txt"); @@ -142,7 +142,7 @@ TEST_SUITE(BufferTests) { CHECK(TestBuf.nlines == 998); CHECK(!strcmp(TestBuf.path, "testdocs/lorem.txt")); } - + TEST(buf_reload should reload the file from disk) { buf_init(&TestBuf, NULL); buf_load(&TestBuf, "testdocs/waf"); @@ -160,7 +160,7 @@ TEST_SUITE(BufferTests) { CHECK(TestBuf.nlines == 998); CHECK(!strcmp(TestBuf.path, "testdocs/lorem.txt")); } - + /* Saving *************************************************************************/ TEST(buf_save should save a UTF-8 file to disk) { @@ -170,7 +170,7 @@ TEST_SUITE(BufferTests) { buf_save(&TestBuf); CHECK(TestBuf.modified == false); } - + TEST(buf_save should save a non UTF-8 file to disk) { buf_init(&TestBuf, NULL); buf_load(&TestBuf, "testdocs/waf"); @@ -178,7 +178,7 @@ TEST_SUITE(BufferTests) { buf_save(&TestBuf); CHECK(TestBuf.modified == false); } - + TEST(buf_save should save a file to disk with unix line endings) { buf_init(&TestBuf, NULL); buf_load(&TestBuf, "testdocs/lf.txt"); @@ -186,7 +186,7 @@ TEST_SUITE(BufferTests) { buf_save(&TestBuf); CHECK(TestBuf.modified == false); } - + TEST(buf_save should save a file to disk with dos line endings) { buf_init(&TestBuf, NULL); buf_load(&TestBuf, "testdocs/crlf.txt"); @@ -194,7 +194,7 @@ TEST_SUITE(BufferTests) { buf_save(&TestBuf); CHECK(TestBuf.modified == false); } - + TEST(buf_save should make sure unix file ends witn newline) { buf_init(&TestBuf, NULL); buf_load(&TestBuf, "testdocs/lf.txt"); @@ -269,7 +269,7 @@ TEST_SUITE(BufferTests) { CHECK(TestBuf.modified == true); CHECK(TestBuf.redo == NULL); } - + TEST(buf_insert should expand tabs) { set_buffer_text(""); TestBuf.expand_tabs = true; @@ -278,7 +278,7 @@ TEST_SUITE(BufferTests) { CHECK(TestBuf.modified == true); CHECK(TestBuf.redo == NULL); } - + TEST(buf_insert should copy indent) { set_buffer_text(" "); TestBuf.copy_indent = true; @@ -298,7 +298,7 @@ TEST_SUITE(BufferTests) { CHECK(TestBuf.modified == true); CHECK(TestBuf.redo == NULL); } - + TEST(buf_delete should delete second char) { set_buffer_text("abc"); buf_delete(&TestBuf, 1, 2); @@ -306,7 +306,7 @@ TEST_SUITE(BufferTests) { CHECK(TestBuf.modified == true); CHECK(TestBuf.redo == NULL); } - + TEST(buf_delete should delete third char) { set_buffer_text("abc"); buf_delete(&TestBuf, 2, 3); @@ -337,7 +337,7 @@ TEST_SUITE(BufferTests) { CHECK(TestBuf.redo != NULL); CHECK(TestBuf.undo == NULL); } - + TEST(buf_undo should undo a delete) { Sel sel; set_buffer_text("a"); -- 2.49.0