diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2011-09-23 09:17:19 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2011-09-23 09:17:19 +0000 |
| commit | 662ba0c904530fff306eaafe5fa347fee71ff67a (patch) | |
| tree | a42843cfe337afe627bbe6c8a22c4c8d6c290870 /src/window.cc | |
| parent | 5ca901644f98f88d9fcfd751d8d6ee580de0147d (diff) | |
Selection: do not use [begin, end) semantics but [first, last]
selections are now defined with inclusive iterators, which means that
Selection(cursor, cursor) is a valid selection of the charateter pointed
by cursor.
On the user interface side, that means that the cursor is now part of
the selection, selectors were adapted to this behavior (and word
selectors are now much more intuitive)
Diffstat (limited to 'src/window.cc')
| -rw-r--r-- | src/window.cc | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/window.cc b/src/window.cc index 1448dc68..4c3b87d9 100644 --- a/src/window.cc +++ b/src/window.cc @@ -7,6 +7,22 @@ namespace Kakoune { +BufferIterator Selection::begin() const +{ + return std::min(m_first, m_last); +} + +BufferIterator Selection::end() const +{ + return std::max(m_first, m_last) + 1; +} + +void Selection::offset(int offset) +{ + m_first += offset; + m_last += offset; +} + Window::Window(Buffer& buffer) : m_buffer(buffer), m_position(0, 0), @@ -27,12 +43,11 @@ void Window::erase() for (auto& sel : m_selections) { - sel.canonicalize(); m_buffer.erase(sel.begin(), sel.end()); sel = Selection(sel.begin(), sel.begin()); } if (not m_selections.empty()) - m_cursor = line_and_column_at(m_selections.back().end()); + m_cursor = line_and_column_at(m_selections.back().last()); m_buffer.end_undo_group(); } @@ -133,10 +148,10 @@ void Window::select(bool append, const Selector& selector) { for (auto& sel : m_selections) { - sel = Selection(sel.begin(), selector(sel.end()).end()); + sel = Selection(sel.first(), selector(sel.last()).last()); } } - m_cursor = line_and_column_at(m_selections.back().end()); + m_cursor = line_and_column_at(m_selections.back().last()); scroll_to_keep_cursor_visible_ifn(); } @@ -160,9 +175,6 @@ void Window::update_display_buffer() SelectionList sorted_selections = m_selections; - for (auto& sel : sorted_selections) - sel.canonicalize(); - std::sort(sorted_selections.begin(), sorted_selections.end(), [](const Selection& lhs, const Selection& rhs) { return lhs.begin() < rhs.begin(); }); |
