From 4d6b8a70e1ea140871455d31172b4e35c3caaa99 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 1 Feb 2015 23:19:07 +0000 Subject: [PATCH] Fix highlighter update with new LineModification behaviour --- src/highlighters.cc | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index 20f09181..0a3733c6 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -741,18 +741,17 @@ void update_matches(const Buffer& buffer, ArrayView modifs, auto ins_pos = matches.begin(); for (auto it = ins_pos; it != matches.end(); ++it) { - auto modif_it = std::lower_bound(modifs.begin(), modifs.end(), it->line, - [](const LineModification& c, const LineCount& l) - { return c.old_line < l; }); + auto modif_it = std::upper_bound(modifs.begin(), modifs.end(), it->line, + [](const LineCount& l, const LineModification& c) + { return l < c.old_line; }); - bool erase = (modif_it != modifs.end() and modif_it->old_line == it->line); - if (not erase and modif_it != modifs.begin()) + bool erase = false; + if (modif_it != modifs.begin()) { auto& prev = *(modif_it-1); erase = it->line < prev.old_line + prev.num_removed; it->line += prev.diff(); } - erase = erase or (it->line >= buffer.line_count()); if (not erase) { @@ -773,9 +772,7 @@ void update_matches(const Buffer& buffer, ArrayView modifs, // try to find new matches in each updated lines for (auto& modif : modifs) { - for (auto line = modif.new_line; - line < modif.new_line + modif.num_added and - line < buffer.line_count(); ++line) + for (auto line = modif.new_line; line < modif.new_line + modif.num_added; ++line) { auto l = buffer[line]; for (RegexIterator it{l.begin(), l.end(), regex}, end{}; it != end; ++it)