]> git.mdlowis.com Git - projs/tide.git/commitdiff
implemented view synchronization logic
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 5 May 2018 03:13:15 +0000 (23:13 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 5 May 2018 03:13:15 +0000 (23:13 -0400)
lib/view.c

index 0539f8cf12cb331cc6612c415900b1460eea915d..fb1d17fbacfcc6e180c6cb2305fa749d2f5307be 100644 (file)
@@ -140,6 +140,7 @@ void view_resize(View* view, size_t width, size_t nrows) {
 }
 
 void view_update(View* view, size_t* csrx, size_t* csry) {
+    /* refill the view contents to make sure updates are visible */
     size_t off = view->rows[view->index]->off;
     clear_rows(view, view->index);
     for (size_t i = 0; i < view->nvisible; i++) {
@@ -165,6 +166,16 @@ void view_update(View* view, size_t* csrx, size_t* csry) {
             }
         }
     }
+    /* sync up the view with the cursor */
+    if (view->sync_flags) {
+        if (view->sync_flags & CENTER) {
+            resize(view, view->width, view->nrows, CSRPOS);
+            view_scroll(view, UP * (view->nvisible/2));
+        } else {
+            view_scrollto(view, CSRPOS);
+        }
+        view->sync_flags = 0;
+    }
 }
 
 Row* view_getrow(View* view, size_t row) {
@@ -358,6 +369,11 @@ Rune view_getrune(View* view) {
 }
 
 void view_scrollto(View* view, size_t csr) {
+    Row* lastrow = view->rows[view->nrows-1];
+    size_t first = view->rows[view->index]->off;
+    size_t last  = lastrow->cols[lastrow->len-1].off;
+    if (csr < first || csr > last)
+        resize(view, view->width, view->nrows, csr);
 }
 
 void view_selectall(View* view) {