aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2020-02-03 13:47:15 +0100
committerMarc André Tanner <mat@brain-dump.org>2020-02-03 14:19:32 +0100
commitd04ab3a885428c10276ade0f0a5995a034330a1f (patch)
tree7c06a3a8a365997ec1adac1b23ff23bbd304bb02 /main.c
parent61ab65ea273b3c2031c90d13e94509bf00519d88 (diff)
downloadvis-d04ab3a885428c10276ade0f0a5995a034330a1f.tar.gz
vis-d04ab3a885428c10276ade0f0a5995a034330a1f.tar.xz
vis: simplify selections_match_next
Introduce utility function to create new anchored, primary selection.
Diffstat (limited to 'main.c')
-rw-r--r--main.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/main.c b/main.c
index 4a59ea9..153ce94 100644
--- a/main.c
+++ b/main.c
@@ -1385,6 +1385,18 @@ static const char *selections_match_word(Vis *vis, const char *keys, const Arg *
return keys;
}
+static const Selection *selection_new_primary(View *view, Filerange *r) {
+ Text *txt = view_text(view);
+ size_t pos = text_char_prev(txt, r->end);
+ Selection *s = view_selections_new(view, pos);
+ if (!s)
+ return NULL;
+ view_selections_set(s, r);
+ view_selections_anchor(s, true);
+ view_selections_primary_set(s);
+ return s;
+}
+
static const char *selections_match_next(Vis *vis, const char *keys, const Arg *arg) {
Text *txt = vis_text(vis);
View *view = vis_view(vis);
@@ -1397,26 +1409,14 @@ static const char *selections_match_next(Vis *vis, const char *keys, const Arg *
if (!buf)
return keys;
Filerange word = text_object_word_find_next(txt, sel.end, buf);
- if (text_range_valid(&word)) {
- size_t pos = text_char_prev(txt, word.end);
- if ((s = view_selections_new(view, pos))) {
- view_selections_set(s, &word);
- view_selections_anchor(s, true);
- view_selections_primary_set(s);
- goto out;
- }
- }
+ if (text_range_valid(&word) && selection_new_primary(view, &word))
+ goto out;
sel = view_selections_get(view_selections(view));
word = text_object_word_find_prev(txt, sel.start, buf);
if (!text_range_valid(&word))
goto out;
- size_t pos = text_char_prev(txt, word.end);
- if ((s = view_selections_new(view, pos))) {
- view_selections_set(s, &word);
- view_selections_anchor(s, true);
- view_selections_primary_set(s);
- }
+ selection_new_primary(view, &word);
out:
free(buf);