Skip to content

Commit

Permalink
vis: implement pairwise selection combinator: longer
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Jun 15, 2017
1 parent 84334e9 commit 2f580dc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static const char *selections_minus(Vis*, const char *keys, const Arg *arg);
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*);
/* 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)
Expand Down Expand Up @@ -300,6 +301,7 @@ enum {
VIS_ACTION_SELECTIONS_MINUS,
VIS_ACTION_SELECTIONS_COMBINE_UNION,
VIS_ACTION_SELECTIONS_COMBINE_INTERSECT,
VIS_ACTION_SELECTIONS_COMBINE_LONGER,
VIS_ACTION_TEXT_OBJECT_WORD_OUTER,
VIS_ACTION_TEXT_OBJECT_WORD_INNER,
VIS_ACTION_TEXT_OBJECT_LONGWORD_OUTER,
Expand Down Expand Up @@ -1100,6 +1102,11 @@ static const KeyAction vis_action[] = {
VIS_HELP("Pairwise intersect with selections from register")
selections_combine, { .combine = combine_intersect }
},
[VIS_ACTION_SELECTIONS_COMBINE_LONGER] = {
"vis-selections-combine-longer",
VIS_HELP("Pairwise combine: take longer")
selections_combine, { .combine = combine_longer }
},
[VIS_ACTION_TEXT_OBJECT_WORD_OUTER] = {
"vis-textobject-word-outer",
VIS_HELP("A word leading and trailing whitespace included")
Expand Down Expand Up @@ -1819,6 +1826,16 @@ static Filerange combine_intersect(const Filerange *r1, const Filerange *r2) {
return text_range_new(MAX(r1->start, r2->start), MIN(r1->end, r2->end));
}

static Filerange combine_longer(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 ? *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);
Expand Down

0 comments on commit 2f580dc

Please sign in to comment.