diff --git a/src/dynamic_selection_list.cc b/src/dynamic_selection_list.cc index e6e32f6d..ab8dc26b 100644 --- a/src/dynamic_selection_list.cc +++ b/src/dynamic_selection_list.cc @@ -21,12 +21,11 @@ DynamicSelectionList& DynamicSelectionList::operator=(SelectionList selections) void DynamicSelectionList::check_invariant() const { #ifdef KAK_DEBUG + if (empty()) + return; const Buffer* buf = &buffer(); - for (auto& sel : *this) - { - kak_assert(buf == &sel.buffer()); - sel.check_invariant(); - } + kak_assert(&front().buffer() == buf); + SelectionList::check_invariant(); #endif } diff --git a/src/selection.cc b/src/selection.cc index 0e6bd710..8830e9e5 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -142,4 +142,17 @@ void SelectionList::update_erase(const BufferCoord& begin, const BufferCoord& en on_buffer_change(*this, begin, end, end.line); } +void SelectionList::check_invariant() const +{ +#ifdef KAK_DEBUG + for (size_t i = 0; i < size(); ++i) + { + auto& sel = (*this)[i]; + sel.check_invariant(); + if (i+1 < size()) + kak_assert(sel.begin() <= (*this)[i+1].begin()); + } +#endif +} + } diff --git a/src/selection.hh b/src/selection.hh index 50b8ad7c..d24bc87e 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -74,6 +74,8 @@ struct SelectionList : std::vector void update_insert(const BufferCoord& begin, const BufferCoord& end); void update_erase(const BufferCoord& begin, const BufferCoord& end); + + void check_invariant() const; }; }