From 6759511b9eb0acd066350f63e0112daf56c501f2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 3 Mar 2017 18:47:11 +0000 Subject: [PATCH] Ensure main selection index is correct directly in SelectionList::remove --- src/normal.cc | 3 --- src/selection.cc | 7 +++++++ src/selection.hh | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index ae59d9fc..4a6588c6 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1717,9 +1717,6 @@ void remove_selection(Context& context, NormalParams p) throw runtime_error{"Cannot remove the last selection"}; selections.remove(index); - size_t main_index = selections.main_index(); - if (index < main_index or main_index == selections.size()) - selections.set_main_index(main_index - 1); selections.check_invariant(); } diff --git a/src/selection.cc b/src/selection.cc index b0474e67..7424067b 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -36,6 +36,13 @@ SelectionList::SelectionList(Buffer& buffer, Vector s, size_t timesta SelectionList::SelectionList(Buffer& buffer, Vector s) : SelectionList(buffer, std::move(s), buffer.timestamp()) {} +void SelectionList::remove(size_t index) +{ + m_selections.erase(begin() + index); + if (index < m_main or m_main == m_selections.size()) + --m_main; +} + namespace { diff --git a/src/selection.hh b/src/selection.hh index 2793fd67..d1fac7fa 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -130,7 +130,7 @@ struct SelectionList const_iterator begin() const { return m_selections.begin(); } const_iterator end() const { return m_selections.end(); } - void remove(size_t index) { m_selections.erase(begin() + index); } + void remove(size_t index); size_t size() const { return m_selections.size(); }