summaryrefslogtreecommitdiff
path: root/src/selectors.cc
diff options
context:
space:
mode:
authorOlivier Perret <Olivier.Perret@mailbox.org>2023-01-20 17:52:44 +0100
committerOlivier Perret <Olivier.Perret@mailbox.org>2023-01-20 18:05:04 +0100
commitb039a313a457c29710fda077f7e69725afd34976 (patch)
tree4cdb6d585ecb7eede8fc9988c1d7b34df53c02c0 /src/selectors.cc
parentd8883d47c0d3e4f967c512213fe7790dc2c1f9f8 (diff)
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
Diffstat (limited to 'src/selectors.cc')
-rw-r--r--src/selectors.cc5
1 files 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<Selection> split_on_matches(const Buffer& buffer, ConstArrayView<Selectio
ThreadedRegexVM<BufferIterator, RegexMode::Forward | RegexMode::Search> 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<Selection> split_on_matches(const Buffer& buffer, ConstArrayView<Selectio
if (end == buf_end)
continue;
- if (end != buf_begin)
+ if (end != sel_begin)
{
auto sel_end = (begin == end) ? end : utf8::previous(end, begin);
result.push_back(keep_direction({ begin.coord(), sel_end.coord() }, sel));