aboutsummaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-04-15 00:05:17 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-04-15 00:07:46 +0200
commite7e1ff75c21f8f29c9b536e12440d58045206845 (patch)
tree95ef8c4aed859210f617f47c8a9f92275ad77a6d /window.c
parent448849f7eb8723a8d11fad287e927c8a8b29cd68 (diff)
downloadvis-e7e1ff75c21f8f29c9b536e12440d58045206845.tar.gz
vis-e7e1ff75c21f8f29c9b536e12440d58045206845.tar.xz
Try to remember column position when moving across lines
This currently only works for non-wrapped lines.
Diffstat (limited to 'window.c')
-rw-r--r--window.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/window.c b/window.c
index 1f22988..df2b069 100644
--- a/window.c
+++ b/window.c
@@ -28,7 +28,9 @@
typedef struct { /* cursor position */
Filepos pos; /* in bytes from the start of the file */
+ Filepos lastpos; /* previous cursor position */
int row, col; /* in terms of zero based screen coordinates */
+ int lastcol; /* remembered column used when moving across lines */
Line *line; /* screen line on which cursor currently resides */
bool highlighted; /* true e.g. when cursor is on a bracket */
} Cursor;
@@ -292,6 +294,9 @@ static size_t window_cursor_update(Win *win) {
window_draw(win);
}
}
+ if (cursor->pos != cursor->lastpos)
+ cursor->lastcol = 0;
+ cursor->lastpos = cursor->pos;
if (win->ui)
win->ui->cursor_to(win->ui, cursor->col, cursor->row);
return cursor->pos;
@@ -753,19 +758,27 @@ size_t window_line_down(Win *win) {
size_t window_screenline_up(Win *win) {
Cursor *cursor = &win->cursor;
+ int lastcol = cursor->lastcol;
+ if (!lastcol)
+ lastcol = cursor->col;
if (!cursor->line->prev)
window_scroll_up(win, 1);
if (cursor->line->prev)
- window_cursor_set(win, cursor->line->prev, cursor->col);
+ window_cursor_set(win, cursor->line->prev, lastcol);
+ cursor->lastcol = lastcol;
return cursor->pos;
}
size_t window_screenline_down(Win *win) {
Cursor *cursor = &win->cursor;
+ int lastcol = cursor->lastcol;
+ if (!lastcol)
+ lastcol = cursor->col;
if (!cursor->line->next && cursor->line == win->bottomline)
window_scroll_down(win, 1);
if (cursor->line->next)
- window_cursor_set(win, cursor->line->next, cursor->col);
+ window_cursor_set(win, cursor->line->next, lastcol);
+ cursor->lastcol = lastcol;
return cursor->pos;
}