]> git.mdlowis.com Git - projs/tide.git/commitdiff
reworked row limiting code to properly handle long lines that wrap in the tag region
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 3 Mar 2017 21:13:55 +0000 (16:13 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 3 Mar 2017 21:13:55 +0000 (16:13 -0500)
TODO.md
lib/view.c

diff --git a/TODO.md b/TODO.md
index 29419dfb3ba795f0494d4979dec30545e6244203..9e35c57fb03169481f8f2d040e53915e042dc86b 100644 (file)
--- 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
 
index eed9f55489f9ef9f137908d606cf8ddfe389ceee..5cca4dde9928785308a8c49050dcdf07c9596a1d 100644 (file)
@@ -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) {