From 77c5bf9f77b0e829d2f8e498deedbe30a0251f33 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 3 Mar 2017 16:13:55 -0500 Subject: [PATCH] reworked row limiting code to properly handle long lines that wrap in the tag region --- TODO.md | 11 +++++------ lib/view.c | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/TODO.md b/TODO.md index 29419df..9e35c57 100644 --- a/TODO.md +++ b/TODO.md @@ -3,30 +3,29 @@ Up Next: * implement 9term-like scrollbar -* tab inserts dont coalesce like one would expect * check for file changes on save * check for file changes when window regains focus * Right click in tags region should search edit region -* Tag line count should account for wrapped lines * ctrl+alt+f should find next occurence of previous search term * Add keyboard shortcut to highlight the thing under the cursor +* 100% coverage with unit and unit-integration tests Tomorrow-ish: -* off by one error on scrolling up with wrapped lines -* add a distinct state for pointer move versus drag +* selecting text should set PRIMARY x11 selection * Add a SaveAs tag that takes an argument for the filename to save as * Add a GoTo tag for ctags lookup and line number jump (or right click magic?) * Add a ctrl+space shortcut to autocomplete ctag -* 100% coverage with unit and unit-integration tests +* off by one error on scrolling up with wrapped lines +* tab inserts dont coalesce like one would expect The Future: * Run commands in the background and don't block the main thread. +* shortcut to repeat previous operation * add command line flags to toggle options (Tabs, Indent, etc..) * add command env vars to set options (Tabs, Indent, etc..) * implement command diffing logic to optimize the undo/redo log -* shortcut to repeat previous operation # Auxillary Programs diff --git a/lib/view.c b/lib/view.c index eed9f55..5cca4dd 100644 --- a/lib/view.c +++ b/lib/view.c @@ -192,19 +192,29 @@ void view_init(View* view, char* file) { } size_t view_limitrows(View* view, size_t maxrows, size_t ncols) { +#if 0 size_t nrows = 0; size_t pos = 0; while (nrows < maxrows && pos < buf_end(&(view->buffer))) { for (size_t x = 0; x < ncols;) { Rune r = buf_get(&(view->buffer), pos++); x += runewidth(x, r); - if (buf_iseol(&(view->buffer), pos)) { - nrows++; + if (buf_iseol(&(view->buffer), pos-1)) break; - } } + nrows++; } return (!nrows ? 1 : nrows); +#else + size_t nrows = 1, pos = 0, col = 0; + while (nrows < maxrows && pos < buf_end(&(view->buffer))) { + Rune r = buf_get(&(view->buffer), pos++); + col += runewidth(col, r); + if (col >= ncols || r == RUNE_CRLF || r == '\n') + col = 0, nrows++; + } + return nrows; +#endif } void view_resize(View* view, size_t nrows, size_t ncols) { -- 2.52.0