1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-24 07:53:41 +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; return std::max(m_first, m_last) + 1;
} }
void Selection::offset(int offset) void Selection::merge_with(const Selection& selection)
{ {
m_first += offset; if (m_first <= m_last)
m_last += offset; 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 struct scoped_undo_group
@ -272,7 +275,7 @@ void Window::select(const Selector& selector, bool append)
{ {
for (auto& sel : m_selections) 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(); scroll_to_keep_cursor_visible_ifn();

View File

@ -21,7 +21,7 @@ struct Selection
const BufferIterator& first() const { return m_first; } const BufferIterator& first() const { return m_first; }
const BufferIterator& last() const { return m_last; } const BufferIterator& last() const { return m_last; }
void offset(int offset); void merge_with(const Selection& selection);
private: private:
DynamicBufferIterator m_first; DynamicBufferIterator m_first;