diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-12-11 19:51:59 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-12-13 18:50:27 +0100 |
| commit | cfd7ee049a7c668bb2269029d159b34d2014ece6 (patch) | |
| tree | dc8d3eef1af8318acde758de012db858d4c36e30 /src/selection.cc | |
| parent | e36bc74f431e2f98f049724536da86af9051811d (diff) | |
move selection updating code out of selection, to DynamicSelectionList
this avoids a lot of unnecessary (add|remove)_change_listener as
creating temporary Selections do not call that anymore.
Use can choose between a SelectionList which or a DynamicSelectionList
depending on wethear the buffer will be modified or not during the
selections lifetime.
Diffstat (limited to 'src/selection.cc')
| -rw-r--r-- | src/selection.cc | 88 |
1 files changed, 3 insertions, 85 deletions
diff --git a/src/selection.cc b/src/selection.cc index 6234e1c2..bc156f26 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -24,62 +24,10 @@ BufferIterator Range::end() const return utf8::next(std::max(m_first, m_last)); } -Selection::Selection(const BufferIterator& first, const BufferIterator& last, - CaptureList captures) - : Range{first, last}, m_captures{std::move(captures)} +void Range::check_invariant() const { - check_invariant(); - register_with_buffer(); -} - -Selection::Selection(const Selection& other) - : Range(other), m_captures(other.m_captures) -{ - register_with_buffer(); -} - -Selection::Selection(Selection&& other) - : Range{other}, - m_captures{std::move(other.m_captures)} -{ - register_with_buffer(); -} - -Selection::~Selection() -{ - unregister_with_buffer(); -} - -Selection& Selection::operator=(const Selection& other) -{ - const bool new_buffer = &first().buffer() != &other.first().buffer(); - if (new_buffer) - unregister_with_buffer(); - - first() = other.first(); - last() = other.last(); - m_captures = other.m_captures; - - if (new_buffer) - register_with_buffer(); - - return *this; -} - -Selection& Selection::operator=(Selection&& other) -{ - const bool new_buffer = &first().buffer() != &other.first().buffer(); - if (new_buffer) - unregister_with_buffer(); - - first() = other.first(); - last() = other.last(); - m_captures = std::move(other.m_captures); - - if (new_buffer) - register_with_buffer(); - - return *this; + assert(utf8::is_character_start(first())); + assert(utf8::is_character_start(last())); } static void avoid_eol(BufferIterator& it) @@ -95,34 +43,4 @@ void Selection::avoid_eol() Kakoune::avoid_eol(last()); } -void Selection::on_insert(const BufferIterator& begin, const BufferIterator& end) -{ - first().on_insert(begin.coord(), end.coord()); - last().on_insert(begin.coord(), end.coord()); - check_invariant(); -} - -void Selection::on_erase(const BufferIterator& begin, const BufferIterator& end) -{ - first().on_erase(begin.coord(), end.coord()); - last().on_erase(begin.coord(), end.coord()); - check_invariant(); -} - -void Selection::register_with_buffer() -{ - first().buffer().add_change_listener(*this); -} - -void Selection::unregister_with_buffer() -{ - first().buffer().remove_change_listener(*this); -} - -void Selection::check_invariant() const -{ - assert(utf8::is_character_start(first())); - assert(utf8::is_character_start(last())); -} - } |
