diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-09-24 13:30:51 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-09-24 13:30:51 +0200 |
| commit | 6e5b0ab026093e39fd863ca605250d9558edce41 (patch) | |
| tree | 96c9f48c078b3beed987716074b77a61a9c0593d | |
| parent | 5993bc8c8fd13e71410d1f8b555665c0b8e95f22 (diff) | |
| download | vis-6e5b0ab026093e39fd863ca605250d9558edce41.tar.gz vis-6e5b0ab026093e39fd863ca605250d9558edce41.tar.xz | |
Implement 'g0', 'gm', 'g$'
| -rw-r--r-- | config.def.h | 3 | ||||
| -rw-r--r-- | vis.c | 6 | ||||
| -rw-r--r-- | window.c | 21 | ||||
| -rw-r--r-- | window.h | 3 |
4 files changed, 31 insertions, 2 deletions
diff --git a/config.def.h b/config.def.h index bab72f5..3061aef 100644 --- a/config.def.h +++ b/config.def.h @@ -130,6 +130,9 @@ static KeyBinding vis_movements[] = { { { NONE('(') }, movement, { .i = MOVE_SENTENCE_PREV } }, { { NONE(')') }, movement, { .i = MOVE_SENTENCE_NEXT } }, { { NONE('g'), NONE('g') }, movement, { .i = MOVE_FILE_BEGIN } }, + { { NONE('g'), NONE('0') }, movement, { .i = MOVE_SCREEN_LINE_BEGIN } }, + { { NONE('g'), NONE('m') }, movement, { .i = MOVE_SCREEN_LINE_MIDDLE} }, + { { NONE('g'), NONE('$') }, movement, { .i = MOVE_SCREEN_LINE_END } }, { { NONE('G') }, movement, { .i = MOVE_LINE } }, { { NONE('|') }, movement, { .i = MOVE_COLUMN } }, { { NONE('n') }, movement, { .i = MOVE_SEARCH_FORWARD } }, @@ -189,6 +189,9 @@ static Operator ops[] = { enum { MOVE_SCREEN_LINE_UP, MOVE_SCREEN_LINE_DOWN, + MOVE_SCREEN_LINE_BEGIN, + MOVE_SCREEN_LINE_MIDDLE, + MOVE_SCREEN_LINE_END, MOVE_LINE_PREV, MOVE_LINE_BEGIN, MOVE_LINE_START, @@ -253,6 +256,9 @@ static size_t window_lines_bottom(const Arg *arg); static Movement moves[] = { [MOVE_SCREEN_LINE_UP] = { .win = window_line_up }, [MOVE_SCREEN_LINE_DOWN]= { .win = window_line_down }, + [MOVE_SCREEN_LINE_BEGIN] = { .win = window_line_begin, .type = CHARWISE }, + [MOVE_SCREEN_LINE_MIDDLE] = { .win = window_line_middle,.type = CHARWISE }, + [MOVE_SCREEN_LINE_END] = { .win = window_line_end, .type = CHARWISE|INCLUSIVE }, [MOVE_LINE_PREV] = { .txt = text_line_prev, .type = LINEWISE }, [MOVE_LINE_BEGIN] = { .txt = text_line_begin, .type = LINEWISE }, [MOVE_LINE_START] = { .txt = text_line_start, .type = LINEWISE }, @@ -79,7 +79,7 @@ static void window_clear(Win *win); static bool window_addch(Win *win, Char *c); static size_t window_cursor_update(Win *win); /* set/move current cursor position to a given (line, column) pair */ -static void window_cursor_set(Win *win, Line *line, int col); +static size_t window_cursor_set(Win *win, Line *line, int col); /* move visible viewport n-lines up/down, redraws the window but does not change * cursor position which becomes invalid and should be corrected by either: * @@ -563,7 +563,7 @@ size_t window_char_next(Win *win) { return window_cursor_update(win); } -static void window_cursor_set(Win *win, Line *line, int col) { +static size_t window_cursor_set(Win *win, Line *line, int col) { int row = 0; size_t pos = win->start; Cursor *cursor = &win->cursor; @@ -589,6 +589,8 @@ static void window_cursor_set(Win *win, Line *line, int col) { cursor->line = line; window_cursor_update(win); + + return pos; } static bool window_viewport_down(Win *win, int n) { @@ -705,6 +707,21 @@ size_t window_line_down(Win *win) { return cursor->pos; } +size_t window_line_begin(Win *win) { + return window_cursor_set(win, win->cursor.line, 0); +} + +size_t window_line_middle(Win *win) { + Cursor *cursor = &win->cursor; + return window_cursor_set(win, cursor->line, cursor->line->width / 2); +} + +size_t window_line_end(Win *win) { + Cursor *cursor = &win->cursor; + int col = cursor->line->width - 1; + return window_cursor_set(win, cursor->line, col >= 0 ? col : 0); +} + void window_update(Win *win) { wnoutrefresh(win->win); } @@ -33,6 +33,9 @@ size_t window_char_next(Win*); size_t window_char_prev(Win*); size_t window_line_down(Win*); size_t window_line_up(Win*); +size_t window_line_begin(Win*); +size_t window_line_middle(Win*); +size_t window_line_end(Win*); /* move window content up/down, but keep cursor position unchanged unless it is * on a now invisible line in which case we try to preserve the column position */ size_t window_slide_up(Win*, int lines); |
