Do not try to extend last match when updating regex matches

It does not work well with regexes starting with a lookbehind, as
we would need to reparse from further away, leading to the last
match just being removed. It seems safer not to remove it, as
the motivating use case (multiline macros) is better left to
regions anyway.

Fixes #440
This commit is contained in:
Maxime Coste 2015-10-18 11:37:04 +01:00
parent 832e9155fa
commit 2cd0ce41ac

View File

@ -359,9 +359,7 @@ private:
// Thanks to the ensure_first_face_is_capture_0 method, we know
// these point to the first/last matches capture 0.
auto first_end = matches.begin()->end;
auto last_begin = (matches.end() - m_faces.size())->begin;
bool remove_last = true;
auto last_end = (matches.end() - m_faces.size())->end;
// add regex matches from new begin to old first match end
if (range.begin < old_range.begin)
@ -371,11 +369,6 @@ private:
add_matches(buffer, new_matches, {range.begin, first_end});
matches.erase(matches.begin(), matches.begin() + m_faces.size());
// first matches was last matches as well, so
// make sure we do not try to remove them again.
if (matches.empty())
remove_last = false;
std::copy(std::make_move_iterator(new_matches.begin()),
std::make_move_iterator(new_matches.end()),
std::inserter(matches, matches.begin()));
@ -384,9 +377,7 @@ private:
if (old_range.end < range.end)
{
old_range.end = range.end;
if (remove_last)
matches.erase(matches.end() - m_faces.size(), matches.end());
add_matches(buffer, matches, {last_begin, range.end});
add_matches(buffer, matches, {last_end, range.end});
}
}
return it->matches;