From d9b1ee13d9c9ac966d0d1bccdd90a39924b68005 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 7 Jun 2017 19:30:44 +0100 Subject: [PATCH] Change merge_overlapping to guarantee we dont break the sorting In certain cases, we could end up with a unsorted selection list, leading to broken invariant. --- src/selection.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/selection.cc b/src/selection.cc index 542c44f5..05095dfa 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -7,13 +7,13 @@ namespace Kakoune { -void Selection::merge_with(const Selection& range) +void Selection::merge_with(const Selection& other) { - m_cursor = range.m_cursor; + m_cursor = other.m_cursor; if (m_anchor < m_cursor) - m_anchor = std::min(m_anchor, range.m_anchor); + m_anchor = std::min(m_anchor, other.m_anchor); if (m_anchor > m_cursor) - m_anchor = std::max(m_anchor, range.m_anchor); + m_anchor = std::max(m_anchor, other.m_anchor); } SelectionList::SelectionList(Buffer& buffer, Selection s, size_t timestamp) @@ -100,7 +100,8 @@ Iterator merge_overlapping(Iterator begin, Iterator end, size_t& main, OverlapsF { if (overlaps(begin[i], begin[j])) { - begin[i].merge_with(begin[j]); + begin[i].min() = std::min(begin[i].min(), begin[j].min()); + begin[i].max() = std::max(begin[i].max(), begin[j].max()); if (i < main) --main; }