Ensure main selection index is correct directly in SelectionList::remove
This commit is contained in:
parent
8a1e5d12ac
commit
6759511b9e
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,13 @@ SelectionList::SelectionList(Buffer& buffer, Vector<Selection> s, size_t timesta
|
|||
SelectionList::SelectionList(Buffer& buffer, Vector<Selection> 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
|
||||
{
|
||||
|
||||
|
|
|
@ -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(); }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user