Skip to content

Commit

Permalink
view: change cursor line up/down off screen movements
Browse files Browse the repository at this point in the history
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 martanne#301
  • Loading branch information
martanne committed Sep 29, 2016
1 parent 5b3c070 commit cab0d2c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions view.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,21 +750,31 @@ 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;
return cursor->pos;
}

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;
Expand Down

0 comments on commit cab0d2c

Please sign in to comment.