From b039a313a457c29710fda077f7e69725afd34976 Mon Sep 17 00:00:00 2001 From: Olivier Perret Date: Fri, 20 Jan 2023 17:52:44 +0100 Subject: [PATCH] fix 'split' operation when the pattern occurs at the beginning Previously it would result in a stray single-character selection at the beginning of the input text. For example: [abcabc] -> split on 'a' -> [a][bc]a[bc] or [foobarfoobar] -> split on 'foo' -> [f]oo[bar]foo[bar] Note that this behavior was not occuring if the input text was at the beginning of the buffer --- src/selectors.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/selectors.cc b/src/selectors.cc index 3d9b453d..2c657b80 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -965,7 +965,8 @@ Vector split_on_matches(const Buffer& buffer, ConstArrayView vm{*regex.impl()}; for (auto& sel : selections) { - auto begin = buffer.iterator_at(sel.min()); + auto sel_begin = buffer.iterator_at(sel.min()); + auto begin = sel_begin; auto sel_end = utf8::next(buffer.iterator_at(sel.max()), buf_end); for (auto&& match : RegexIterator{begin, sel_end, vm, match_flags(buffer, begin, sel_end)}) @@ -975,7 +976,7 @@ Vector split_on_matches(const Buffer& buffer, ConstArrayView