aboutsummaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-24 13:30:51 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-24 13:30:51 +0200
commit6e5b0ab026093e39fd863ca605250d9558edce41 (patch)
tree96c9f48c078b3beed987716074b77a61a9c0593d /window.c
parent5993bc8c8fd13e71410d1f8b555665c0b8e95f22 (diff)
downloadvis-6e5b0ab026093e39fd863ca605250d9558edce41.tar.gz
vis-6e5b0ab026093e39fd863ca605250d9558edce41.tar.xz
Implement 'g0', 'gm', 'g$'
Diffstat (limited to 'window.c')
-rw-r--r--window.c21
1 files changed, 19 insertions, 2 deletions
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);
}