Skip to content

Commit

Permalink
on <C-n>, flip new selection if the old selection was flipped
Browse files Browse the repository at this point in the history
raised in issue 1022: martanne#1022
  • Loading branch information
jeremybobbin committed Mar 12, 2023
1 parent 4e8709a commit 1c2128c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1394,25 +1394,37 @@ static const char *selections_match_next(Vis *vis, const char *keys, const Arg *
if (!buf)
return keys;

bool flip;
bool match_all = arg->b;
Filerange primary = range;
Selection *sel;

for (;;) {
flip = view_cursor_get(view) == primary.start;
range = find_next(txt, range.end, buf);
if (!text_range_valid(&range))
break;
if (selection_new(view, &range, !match_all) && !match_all)
goto out;
if (sel = selection_new(view, &range, !match_all)) {
if (flip)
view_selections_flip(sel);
if (!match_all)
goto out;
}
}

range = primary;

for (;;) {
flip = view_cursor_get(view) == primary.start;
range = find_prev(txt, range.start, buf);
if (!text_range_valid(&range))
break;
if (selection_new(view, &range, !match_all) && !match_all)
break;
if (sel = selection_new(view, &range, !match_all)) {
if (flip)
view_selections_flip(sel);
if (!match_all)
break;
}
}

out:
Expand Down

0 comments on commit 1c2128c

Please sign in to comment.