From 6e5b0ab026093e39fd863ca605250d9558edce41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 24 Sep 2014 13:30:51 +0200 Subject: Implement 'g0', 'gm', 'g$' --- window.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index 716d9e5..cb22f56 100644 --- a/window.c +++ b/window.c @@ -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); } -- cgit v1.2.3