vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit c91af13c9186676b3bdd10e301b811f5376e7eca
parent 98f2b02a67f8cb55cbd222d4407288e211339985
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Mon, 26 Sep 2016 22:04:05 +0200

view: change cursor line up/down off screen movements

Previously the cursor would be placed in the middle of
the screen thus causing a distracting jump. Instead try
to scroll the view port by only 1 line when the cursor
is moved out of the visible area.

The current implementation might be quite a bit slower
than before, use page-wise scrolling to skip large
regions.

At some point we should optimize motions like 1000j.

Close #301

Diffstat:
Mview.c | 14++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/view.c b/view.c @@ -750,10 +750,15 @@ size_t view_scroll_down(View *view, int lines) { } size_t view_line_up(Cursor *cursor) { + View *view = cursor->view; int lastcol = cursor->lastcol; if (!lastcol) lastcol = cursor->col; - view_cursors_to(cursor, text_line_up(cursor->view->text, cursor->pos)); + size_t pos = text_line_up(cursor->view->text, cursor->pos); + bool offscreen = view->cursor == cursor && pos < view->start; + view_cursors_to(cursor, pos); + if (offscreen) + view_redraw_top(view); if (cursor->line) cursor_set(cursor, cursor->line, lastcol); cursor->lastcol = lastcol; @@ -761,10 +766,15 @@ size_t view_line_up(Cursor *cursor) { } size_t view_line_down(Cursor *cursor) { + View *view = cursor->view; int lastcol = cursor->lastcol; if (!lastcol) lastcol = cursor->col; - view_cursors_to(cursor, text_line_down(cursor->view->text, cursor->pos)); + size_t pos = text_line_down(cursor->view->text, cursor->pos); + bool offscreen = view->cursor == cursor && pos > view->end; + view_cursors_to(cursor, pos); + if (offscreen) + view_redraw_bottom(view); if (cursor->line) cursor_set(cursor, cursor->line, lastcol); cursor->lastcol = lastcol;