aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-03-10 20:56:24 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-03-10 22:36:54 +0100
commitd268609511dc77e1acbd3885642b82751d32bccc (patch)
treeb26baf503ce83aedcd059a6771809fdad69428b9 /main.c
parent5e632554d9bf7ea48783702ea59585639e1797bf (diff)
downloadvis-d268609511dc77e1acbd3885642b82751d32bccc.tar.gz
vis-d268609511dc77e1acbd3885642b82751d32bccc.tar.xz
vis: let <C-u> and <C-d> in visual mode move to prev/next cursor
We do currently not enforce a strict ordering among cursors. Hence these key bindings can move you to an arbitray position. In practice it somewhat works because most of the time cursors are created in "top-down" i.e from the start of the file towards the end.
Diffstat (limited to 'main.c')
-rw-r--r--main.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/main.c b/main.c
index 8a0487b..bb6f8cf 100644
--- a/main.c
+++ b/main.c
@@ -48,6 +48,8 @@ static const char *cursors_align_indent(Vis*, const char *keys, const Arg *arg);
static const char *cursors_clear(Vis*, const char *keys, const Arg *arg);
/* remove the least recently added cursor */
static const char *cursors_remove(Vis*, const char *keys, const Arg *arg);
+/* move to the previous (arg->i < 0) or next (arg->i > 0) cursor */
+static const char *cursors_navigate(Vis*, const char *keys, const Arg *arg);
/* select the word the cursor is currently over */
static const char *cursors_select(Vis*, const char *keys, const Arg *arg);
/* select the next region matching the current selection */
@@ -244,6 +246,8 @@ enum {
VIS_ACTION_CURSORS_ALIGN_INDENT,
VIS_ACTION_CURSORS_REMOVE_ALL,
VIS_ACTION_CURSORS_REMOVE_LAST,
+ VIS_ACTION_CURSORS_PREV,
+ VIS_ACTION_CURSORS_NEXT,
VIS_ACTION_TEXT_OBJECT_WORD_OUTER,
VIS_ACTION_TEXT_OBJECT_WORD_INNER,
VIS_ACTION_TEXT_OBJECT_LONGWORD_OUTER,
@@ -929,6 +933,16 @@ static const KeyAction vis_action[] = {
"Remove least recently created cursor",
cursors_remove,
},
+ [VIS_ACTION_CURSORS_PREV] = {
+ "cursors-prev",
+ "Move to the previous cursor",
+ cursors_navigate, { .i = -PAGE_HALF }
+ },
+ [VIS_ACTION_CURSORS_NEXT] = {
+ "cursors-next",
+ "Move to the next cursor",
+ cursors_navigate, { .i = +PAGE_HALF }
+ },
[VIS_ACTION_TEXT_OBJECT_WORD_OUTER] = {
"text-object-word-outer",
"A word leading and trailing whitespace included",
@@ -1301,6 +1315,28 @@ static const char *cursors_remove(Vis *vis, const char *keys, const Arg *arg) {
return keys;
}
+static const char *cursors_navigate(Vis *vis, const char *keys, const Arg *arg) {
+ View *view = vis_view(vis);
+ bool multiple_cursors = view_cursors_next(view_cursors(view));
+ if (!multiple_cursors)
+ return wscroll(vis, keys, arg);
+ Cursor *c = view_cursors_primary_get(view);
+ if (arg->i < 0) {
+ c = view_cursors_next(c);
+ if (!c)
+ c = view_cursors(view);
+ } else {
+ c = view_cursors_prev(c);
+ if (!c) {
+ c = view_cursors(view);
+ for (Cursor *n = c; n; n = view_cursors_next(n))
+ c = n;
+ }
+ }
+ view_cursors_primary_set(c);
+ return keys;
+}
+
static const char *replace(Vis *vis, const char *keys, const Arg *arg) {
if (!keys[0])
return NULL;