diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-09-27 19:51:29 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-09-27 19:51:29 +0200 |
| commit | 521263a2c67d2b5df507858dcd240a9e42790780 (patch) | |
| tree | 2967b3b921f4e5568825367bbeb367f3f918a19d /window.c | |
| parent | ab264837f7c127ba8ff4666f9c4ed94efd485af0 (diff) | |
| download | vis-521263a2c67d2b5df507858dcd240a9e42790780.tar.gz vis-521263a2c67d2b5df507858dcd240a9e42790780.tar.xz | |
Implement 'zt', 'zz', 'zb'
In particular 'zb' might not work if there are wrapped lines involved.
Diffstat (limited to 'window.c')
| -rw-r--r-- | window.c | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -639,6 +639,48 @@ static bool window_viewport_up(Win *win, int n) { return true; } +void window_redraw_top(Win *win) { + Line *line = win->cursor.line; + for (Line *cur = win->topline; cur && cur != line; cur = cur->next) + win->start += cur->len; + window_draw(win); + window_cursor_to(win, win->cursor.pos); +} + +void window_redraw_center(Win *win) { + int center = win->height / 2; + size_t pos = win->cursor.pos; + for (int i = 0; i < 2; i++) { + int linenr = 0; + Line *line = win->cursor.line; + for (Line *cur = win->topline; cur && cur != line; cur = cur->next) + linenr++; + if (linenr < center) { + window_slide_down(win, center - linenr); + continue; + } + for (Line *cur = win->topline; cur && cur != line && linenr > center; cur = cur->next) { + win->start += cur->len; + linenr--; + } + break; + } + window_draw(win); + window_cursor_to(win, pos); +} + +void window_redraw_bottom(Win *win) { + Line *line = win->cursor.line; + if (line == win->lastline) + return; + int linenr = 0; + size_t pos = win->cursor.pos; + for (Line *cur = win->topline; cur && cur != line; cur = cur->next) + linenr++; + window_slide_down(win, win->height - linenr - 1); + window_cursor_to(win, pos); +} + size_t window_slide_up(Win *win, int lines) { Cursor *cursor = &win->cursor; if (window_viewport_down(win, lines)) { |
