]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed line number and scrolling behavior on undo/redo
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 16 Jun 2017 00:02:24 +0000 (20:02 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 16 Jun 2017 00:02:24 +0000 (20:02 -0400)
TODO.md
lib/view.c

diff --git a/TODO.md b/TODO.md
index aad1b5315f0779f912bd720ef8e9fa312dcfcc3b..c358c3a918e6a40ec43e87f9d5e720f92d2cccf0 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -2,6 +2,8 @@
 
 Up Next:
 
+* add a cap to the distance from last span to first char on screen
+* Ctrl+/ shortcut to comment/uncomment based on syntax
 * Update click time to 500ms
 * ignore the menu key or map it to control
 * clicking or dragging the mouse out of bounds should still update the selection
index 72a86ed0f89733442ab38afa8630dcaf1714d9e0..89872658c6713eed9a9af8fc00483a23bf9a3a15 100644 (file)
@@ -105,11 +105,8 @@ void view_update(View* view, size_t* csrx, size_t* csry) {
     find_cursor(view, csrx, csry);
 
     /* synchronize, scan for, and apply highlighted regions */
-    if (!view->syntax) return;
-    size_t first = (view->nrows ? view->rows[0]->off : 0),
-           last  = buf_end(&(view->buffer));
-    if (view->nrows)
-        last = view->rows[view->nrows-1]->off + view->rows[view->nrows-1]->rlen;
+    size_t first = view->rows[0]->off,
+           last  = view->rows[view->nrows-1]->off + view->rows[view->nrows-1]->rlen;
     view->spans = colors_rewind(view->spans, first);
     first = (view->spans ? view->spans->end : 0);
     view->spans = colors_scan(view->syntax, view->spans, &(view->buffer), first, last+1);
@@ -275,23 +272,17 @@ void view_setln(View* view, size_t line) {
 void view_undo(View* view) {
     view->prev_csr = view->selection.end;
     buf_undo(&(view->buffer), &(view->selection));
-    view->sync_lines = true;
-    if (!selection_visible(view)) {
-        view->sync_center = true;
-        if (view->nrows)
-            view->rows[0]->off = buf_bol(&(view->buffer), view->selection.beg);
-    }
+    view->sync_needed = true;
+    view->sync_lines  = true;
+    view->sync_center = !selection_visible(view);
 }
 
 void view_redo(View* view) {
     view->prev_csr = view->selection.end;
     buf_redo(&(view->buffer), &(view->selection));
-    view->sync_lines = true;
-    if (!selection_visible(view)) {
-        view->sync_center = true;
-        if (view->nrows)
-            view->rows[0]->off = buf_bol(&(view->buffer), view->selection.beg);
-    }
+    view->sync_needed = true;
+    view->sync_lines  = true;
+    view->sync_center = !selection_visible(view);
 }
 
 void view_putstr(View* view, char* str) {
@@ -514,12 +505,11 @@ static bool in_selection(Sel sel, size_t off) {
 
 static bool selection_visible(View* view) {
     if (!view->nrows) return true;
-    Sel sel = view->selection;
-    selswap(&sel);
+    size_t csr = view->selection.end;
     size_t beg = view->rows[0]->off;
     size_t end = view->rows[view->nrows-1]->off +
                  view->rows[view->nrows-1]->rlen;
-    return (sel.beg >= beg && sel.end <= end);
+    return (beg <= csr && csr <= end);
 }
 
 static void find_cursor(View* view, size_t* csrx, size_t* csry) {