aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-06-15 13:37:39 +0200
committerMarc André Tanner <mat@brain-dump.org>2017-06-15 15:51:43 +0200
commit8f7f5df4ef27882f3babbc586302ecd907869e3e (patch)
treee9fd7015d2621e1b0f9042647734cbe9fd21a053
parent898dcf0e49bb7da186052b249a1366273d102095 (diff)
downloadvis-8f7f5df4ef27882f3babbc586302ecd907869e3e.tar.gz
vis-8f7f5df4ef27882f3babbc586302ecd907869e3e.tar.xz
vis: implement pairwise selection combinator: rightmost
-rw-r--r--main.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/main.c b/main.c
index 3905aa6..b3d760f 100644
--- a/main.c
+++ b/main.c
@@ -93,6 +93,7 @@ static Filerange combine_intersect(const Filerange*, const Filerange*);
static Filerange combine_longer(const Filerange*, const Filerange*);
static Filerange combine_shorter(const Filerange*, const Filerange*);
static Filerange combine_leftmost(const Filerange*, const Filerange*);
+static Filerange combine_rightmost(const Filerange*, const Filerange*);
/* adjust current used count according to keys */
static const char *count(Vis*, const char *keys, const Arg *arg);
/* move to the count-th line or if not given either to the first (arg->i < 0)
@@ -306,6 +307,7 @@ enum {
VIS_ACTION_SELECTIONS_COMBINE_LONGER,
VIS_ACTION_SELECTIONS_COMBINE_SHORTER,
VIS_ACTION_SELECTIONS_COMBINE_LEFTMOST,
+ VIS_ACTION_SELECTIONS_COMBINE_RIGHTMOST,
VIS_ACTION_TEXT_OBJECT_WORD_OUTER,
VIS_ACTION_TEXT_OBJECT_WORD_INNER,
VIS_ACTION_TEXT_OBJECT_LONGWORD_OUTER,
@@ -1121,6 +1123,11 @@ static const KeyAction vis_action[] = {
VIS_HELP("Pairwise combine: leftmost")
selections_combine, { .combine = combine_leftmost }
},
+ [VIS_ACTION_SELECTIONS_COMBINE_RIGHTMOST] = {
+ "vis-selections-combine-rightmost",
+ VIS_HELP("Pairwise combine: rightmost")
+ selections_combine, { .combine = combine_rightmost }
+ },
[VIS_ACTION_TEXT_OBJECT_WORD_OUTER] = {
"vis-textobject-word-outer",
VIS_HELP("A word leading and trailing whitespace included")
@@ -1868,6 +1875,14 @@ static Filerange combine_leftmost(const Filerange *r1, const Filerange *r2) {
return r1->start < r2->start || (r1->start == r2->start && r1->end < r2->end) ? *r1 : *r2;
}
+static Filerange combine_rightmost(const Filerange *r1, const Filerange *r2) {
+ if (!r1)
+ return *r2;
+ if (!r2)
+ return *r1;
+ return r1->start < r2->start || (r1->start == r2->start && r1->end < r2->end) ? *r2 : *r1;
+}
+
static const char *selections_combine(Vis *vis, const char *keys, const Arg *arg) {
View *view = vis_view(vis);
enum VisRegister reg = vis_register_used(vis);