diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-09-26 22:04:05 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-09-29 21:46:04 +0200 |
| commit | cab0d2ce3f375084dd2de764e760ccc229689b71 (patch) | |
| tree | 9fe5e0312d9d9c65e979b4a5a11ec5c2d3979175 | |
| parent | 5b3c070e979b4a61659eae33668d702ef97291a2 (diff) | |
| download | vis-cab0d2ce3f375084dd2de764e760ccc229689b71.tar.gz vis-cab0d2ce3f375084dd2de764e760ccc229689b71.tar.xz | |
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
| -rw-r--r-- | view.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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; |
