aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-03-27 16:14:48 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-03-28 12:25:05 +0200
commit8965cd21386683cae680ba7de4b6a6ee6687e17f (patch)
treeb4920c2958069cff877a778bf0dbf3e8578e71a9 /main.c
parentf567d332bec0e7d31b7214e4065663e5349b2252 (diff)
downloadvis-8965cd21386683cae680ba7de4b6a6ee6687e17f.tar.gz
vis-8965cd21386683cae680ba7de4b6a6ee6687e17f.tar.xz
view: change cursor creation API to take an initial position
Diffstat (limited to 'main.c')
-rw-r--r--main.c22
1 files changed, 11 insertions, 11 deletions
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;
}