Selection: more intelligent merging
This commit is contained in:
parent
62482b65ec
commit
55cd4949e0
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user