From: Michael D. Lowis Date: Tue, 2 May 2017 17:21:29 +0000 (-0400) Subject: undo/redo should only center selection if the selection was off screen. X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=a80bd960bfc63715b7ff0e3a1eb16cef20fec000;p=projs%2Ftide.git undo/redo should only center selection if the selection was off screen. --- diff --git a/lib/view.c b/lib/view.c index 22d543b..0422982 100644 --- a/lib/view.c +++ b/lib/view.c @@ -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) {