From cab0d2ce3f375084dd2de764e760ccc229689b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Mon, 26 Sep 2016 22:04:05 +0200 Subject: 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 --- view.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'view.c') diff --git a/view.c b/view.c index 2d4730d..8f37dcc 100644 --- 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; -- cgit v1.2.3