diff options
| author | Johannes Altmanninger <aclopte@gmail.com> | 2025-05-10 21:23:31 +0200 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2025-05-11 09:57:17 +1000 |
| commit | a89747c458b7e316ba78fc0a52fad36f827dd63f (patch) | |
| tree | 9ab09d530699343c53a33f0dee8191660989cc4d /src | |
| parent | 3241f1b63025ebad4f8706594acf265f0e5e9c4a (diff) | |
Fix <a-?> crash when first selection wraps
The <?> and <a-?> commands drop selections where the search wrapped.
If a selection is dropped this way, we adjust the new main index.
If the very first selection is dropped this way, *and* it happens to
be the main index, "--main_index" overflows and chaos ensues.
Fix this by saturating main index at zero. This seems more intuitive
than wrapping around ("% new_sels.size()").
This issue only happens to <a-?>, not <?>. When <?> wraps when starting
from the first selection, it necessarily also wraps after all other
selections. (Based on this insight, I started drafting an optimization
to skip searches whose results would be discarded anyway because they
will definitely wrap. Not sure if it's worth it, since it applies
only to the rare edge case of <?>/<a-?> with multiple selections.)
Fixes #5314
Diffstat (limited to 'src')
| -rw-r--r-- | src/normal.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/normal.cc b/src/normal.cc index 8a8b958d..ba5b6e06 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -947,7 +947,7 @@ void extend_to_next_matches(Context& context, const Regex& regex, RegexMode mode new_sels.push_back(sel); merge_selections(new_sels.back(), new_sel); } - else if (new_sels.size() <= main_index) + else if (new_sels.size() <= main_index and main_index != 0) --main_index; } if (new_sels.empty()) |
