From 2cd0ce41ac8678a766b8838d37bc0a54a9935b95 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 18 Oct 2015 11:37:04 +0100 Subject: [PATCH] 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 --- src/highlighters.cc | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index 3bbccca8..648e6072 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -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;