]> git.mdlowis.com Git - projs/tide.git/commitdiff
undo/redo should only center selection if the selection was off screen.
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 2 May 2017 17:21:29 +0000 (13:21 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 2 May 2017 17:21:29 +0000 (13:21 -0400)
lib/view.c

index 22d543b5d1f76f03289ca6d21a783dc7a534be03..042298296eb2e936b683d63a7629c47b9e987c43 100644 (file)
@@ -433,16 +433,24 @@ void view_setln(View* view, size_t line) {
     view->sync_center = true;
 }
 
+static bool selvisible(View* view) {
+    if (!view->nrows) return true;
+    unsigned beg = view->rows[0]->off;
+    unsigned end = view->rows[view->nrows-1]->off + 
+                   view->rows[view->nrows-1]->rlen;
+    return (view->selection.beg >= beg && view->selection.end <= end);
+}
+
 void view_undo(View* view) {
     buf_undo(&(view->buffer), &(view->selection));
     view_jumpto(view, true, view->selection.end);
-    view->sync_center = true;
+    view->sync_center = !selvisible(view);
 }
 
 void view_redo(View* view) {
     buf_redo(&(view->buffer), &(view->selection));
     view_jumpto(view, true, view->selection.end);
-    view->sync_center = true;
+    view->sync_center = !selvisible(view);
 }
 
 void view_putstr(View* view, char* str) {