1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-23 23:34:12 +03:00

Selection: more intelligent merging

This commit is contained in:
Maxime Coste 2011-10-27 14:22:17 +00:00
parent 62482b65ec
commit 55cd4949e0
2 changed files with 8 additions and 5 deletions

View File

@ -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();

View File

@ -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;