aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-06-15 13:32:31 +0200
committerMarc André Tanner <mat@brain-dump.org>2017-06-15 15:51:43 +0200
commitc5082c9bcb9ab08fcb90b895ec59a90a9c86e5d9 (patch)
tree39f4fb4f2c25b68102dbca62cd26f3d8fe2d29dd
parent2f580dcdba8d8b3097e61770740f3b4f8a2e90e9 (diff)
downloadvis-c5082c9bcb9ab08fcb90b895ec59a90a9c86e5d9.tar.gz
vis-c5082c9bcb9ab08fcb90b895ec59a90a9c86e5d9.tar.xz
vis: implement pairwise selection combinator: shorter
-rw-r--r--main.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/main.c b/main.c
index 77316b5..65f9d59 100644
--- a/main.c
+++ b/main.c
@@ -91,6 +91,7 @@ static const char *selections_combine(Vis*, const char *keys, const Arg *arg);
static Filerange combine_union(const Filerange*, const Filerange*);
static Filerange combine_intersect(const Filerange*, const Filerange*);
static Filerange combine_longer(const Filerange*, const Filerange*);
+static Filerange combine_shorter(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)
@@ -302,6 +303,7 @@ enum {
VIS_ACTION_SELECTIONS_COMBINE_UNION,
VIS_ACTION_SELECTIONS_COMBINE_INTERSECT,
VIS_ACTION_SELECTIONS_COMBINE_LONGER,
+ VIS_ACTION_SELECTIONS_COMBINE_SHORTER,
VIS_ACTION_TEXT_OBJECT_WORD_OUTER,
VIS_ACTION_TEXT_OBJECT_WORD_INNER,
VIS_ACTION_TEXT_OBJECT_LONGWORD_OUTER,
@@ -1107,6 +1109,11 @@ static const KeyAction vis_action[] = {
VIS_HELP("Pairwise combine: take longer")
selections_combine, { .combine = combine_longer }
},
+ [VIS_ACTION_SELECTIONS_COMBINE_SHORTER] = {
+ "vis-selections-combine-shorter",
+ VIS_HELP("Pairwise combine: take shorter")
+ selections_combine, { .combine = combine_shorter }
+ },
[VIS_ACTION_TEXT_OBJECT_WORD_OUTER] = {
"vis-textobject-word-outer",
VIS_HELP("A word leading and trailing whitespace included")
@@ -1836,6 +1843,16 @@ static Filerange combine_longer(const Filerange *r1, const Filerange *r2) {
return l1 < l2 ? *r2 : *r1;
}
+static Filerange combine_shorter(const Filerange *r1, const Filerange *r2) {
+ if (!r1)
+ return *r2;
+ if (!r2)
+ return *r1;
+ size_t l1 = text_range_size(r1);
+ size_t l2 = text_range_size(r2);
+ return l1 < l2 ? *r1 : *r2;
+}
+
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);