Fix splitting selecting the first buffer char when there is a match at buffer begin

This commit is contained in:
Maxime Coste 2016-04-30 10:37:31 +01:00
parent da40828801
commit 25a31534ec
4 changed files with 11 additions and 2 deletions

View File

@ -654,6 +654,7 @@ void split_selections(SelectionList& selections, const Regex& regex, unsigned ca
Vector<Selection> result; Vector<Selection> result;
auto& buffer = selections.buffer(); auto& buffer = selections.buffer();
auto buf_end = buffer.end(); auto buf_end = buffer.end();
auto buf_begin = buffer.begin();
for (auto& sel : selections) for (auto& sel : selections)
{ {
auto begin = buffer.iterator_at(sel.min()); auto begin = buffer.iterator_at(sel.min());
@ -671,8 +672,12 @@ void split_selections(SelectionList& selections, const Regex& regex, unsigned ca
if (end == buf_end) if (end == buf_end)
continue; continue;
end = ensure_char_start(buffer, end); if (end != buf_begin)
result.push_back(keep_direction({ begin.coord(), (begin == end) ? end.coord() : utf8::previous(end, begin).coord() }, sel)); {
end = ensure_char_start(buffer, end);
auto sel_end = (begin == end) ? end : utf8::previous(end, begin);
result.push_back(keep_direction({ begin.coord(), sel_end.coord() }, sel));
}
begin = ensure_char_start(buffer, (*re_it)[capture].second); begin = ensure_char_start(buffer, (*re_it)[capture].second);
} }
if (begin.coord() <= sel.max()) if (begin.coord() <= sel.max())

View File

@ -0,0 +1 @@
%S\w+<ret>

View File

@ -0,0 +1 @@
foo bar baz

View File

@ -0,0 +1,2 @@
: :