From 0803eef3ecf0f585a8ecbc0b9e009864111ba0be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 19 Jan 2017 15:34:45 +0100 Subject: vis: make in visual mode wrap around Strictly speaking we actually not wrap around, but search backwards starting from the first cursor. This is seems more useful when for example renaming a local variable but not starting from its declaration. Close #305 --- main.c | 19 +++++++++++++------ 1 file 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; } -- cgit v1.2.3