diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-01-13 19:41:56 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-01-13 23:01:09 +0100 |
| commit | ff587fb25a56656a9a426a5086b47a5cf891092b (patch) | |
| tree | 911915a3d8ecca9f48effe889bd069776d0f2472 /window.c | |
| parent | cad4ad2c4e9de198ca78958b4db79886ffb81c56 (diff) | |
| download | vis-ff587fb25a56656a9a426a5086b47a5cf891092b.tar.gz vis-ff587fb25a56656a9a426a5086b47a5cf891092b.tar.xz | |
Add new logical linewise movements
The column position is currently not correctly preserved when
there are lines with multibyte characters involved spanning
multiple screen lines.
In general this might still be a bit fragile.
Diffstat (limited to 'window.c')
| -rw-r--r-- | window.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -788,6 +788,30 @@ size_t window_scroll_down(Win *win, int lines) { return cursor->pos; } +size_t window_line_up(Win *win) { + Cursor *cursor = &win->cursor; + if (cursor->line->prev && cursor->line->prev->prev && + cursor->line->lineno != cursor->line->prev->lineno && + cursor->line->prev->lineno != cursor->line->prev->prev->lineno) + return window_screenline_up(win); + size_t bol = text_line_begin(win->text, cursor->pos); + size_t prev = text_line_prev(win->text, bol); + size_t pos = text_line_offset(win->text, prev, cursor->pos - bol); + window_cursor_to(win, pos); + return cursor->pos; +} + +size_t window_line_down(Win *win) { + Cursor *cursor = &win->cursor; + if (!cursor->line->next || cursor->line->next->lineno != cursor->line->lineno) + return window_screenline_down(win); + size_t bol = text_line_begin(win->text, cursor->pos); + size_t next = text_line_next(win->text, bol); + size_t pos = text_line_offset(win->text, next, cursor->pos - bol); + window_cursor_to(win, pos); + return cursor->pos; +} + size_t window_screenline_up(Win *win) { Cursor *cursor = &win->cursor; if (!cursor->line->prev) |
