From 8965cd21386683cae680ba7de4b6a6ee6687e17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sun, 27 Mar 2016 16:14:48 +0200 Subject: view: change cursor creation API to take an initial position --- main.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 95786be..bbb8f10 100644 --- a/main.c +++ b/main.c @@ -1190,15 +1190,15 @@ static const char *repeat(Vis *vis, const char *keys, const Arg *arg) { static const char *cursors_new(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); - size_t pos = view_cursor_get(view); - Cursor *cursor = view_cursors_new(view); - if (cursor) { - view_cursors_to(cursor, pos); - if (arg->i > 0) - view_line_down(cursor); - else if (arg->i < 0) - view_line_up(cursor); - } + Cursor *cursor = view_cursors_primary_get(view); + size_t oldpos = view_cursors_pos(cursor); + if (arg->i > 0) + view_line_down(cursor); + else if (arg->i < 0) + view_line_up(cursor); + size_t newpos = view_cursors_pos(cursor); + view_cursors_to(cursor, oldpos); + view_cursors_new(view, newpos); return keys; } @@ -1294,11 +1294,11 @@ static const char *cursors_select_next(Vis *vis, const char *keys, const Arg *ar free(buf); if (text_range_valid(&word)) { - cursor = view_cursors_new(view); + size_t pos = text_char_prev(txt, word.end); + cursor = view_cursors_new(view, pos); if (!cursor) return keys; view_cursors_selection_set(cursor, &word); - view_cursors_to(cursor, text_char_prev(txt, word.end)); } return keys; } -- cgit v1.2.3