diff --git a/src/window.cc b/src/window.cc index 5f10618c0..837625879 100644 --- a/src/window.cc +++ b/src/window.cc @@ -19,10 +19,13 @@ BufferIterator Selection::end() const return std::max(m_first, m_last) + 1; } -void Selection::offset(int offset) +void Selection::merge_with(const Selection& selection) { - m_first += offset; - m_last += offset; + if (m_first <= m_last) + m_first = std::min(m_first, selection.m_first); + else + m_first = std::max(m_first, selection.m_first); + m_last = selection.m_last; } struct scoped_undo_group @@ -272,7 +275,7 @@ void Window::select(const Selector& selector, bool append) { for (auto& sel : m_selections) { - sel = Selection(sel.first(), selector(sel.last()).last()); + sel.merge_with(selector(sel.last())); } } scroll_to_keep_cursor_visible_ifn(); diff --git a/src/window.hh b/src/window.hh index 2b62794b1..843bdb4f2 100644 --- a/src/window.hh +++ b/src/window.hh @@ -21,7 +21,7 @@ struct Selection const BufferIterator& first() const { return m_first; } const BufferIterator& last() const { return m_last; } - void offset(int offset); + void merge_with(const Selection& selection); private: DynamicBufferIterator m_first;