aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/main.c b/main.c
index 7926c4d..a42d8cd 100644
--- a/main.c
+++ b/main.c
@@ -1442,15 +1442,22 @@ static const char *cursors_select_next(Vis *vis, const char *keys, const Arg *ar
if (!buf)
return keys;
Filerange word = text_object_word_find_next(txt, sel.end, buf);
- free(buf);
-
if (text_range_valid(&word)) {
size_t pos = text_char_prev(txt, word.end);
- cursor = view_cursors_new(view, pos);
- if (!cursor)
- return keys;
- view_cursors_selection_set(cursor, &word);
+ if ((cursor = view_cursors_new(view, pos))) {
+ view_cursors_selection_set(cursor, &word);
+ goto out;
+ }
}
+
+ sel = view_cursors_selection_get(view_cursors(view));
+ word = text_object_word_find_prev(txt, sel.start, buf);
+ size_t pos = text_char_prev(txt, word.end);
+ if ((cursor = view_cursors_new(view, pos)))
+ view_cursors_selection_set(cursor, &word);
+
+out:
+ free(buf);
return keys;
}