From 3453ebbd524de51d8c404904bb6cf31d792d9a10 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 1 Jun 2013 00:48:46 +0200 Subject: [PATCH] BufferChangeListener: pass buffer to on_{inser,erase} --- src/buffer.cc | 4 ++-- src/buffer.hh | 4 ++-- src/dynamic_selection_list.cc | 8 ++++---- src/dynamic_selection_list.hh | 4 ++-- src/editor.cc | 16 +++++++-------- src/highlighters.cc | 4 ++-- src/selection.cc | 37 ++++++++++++++++++----------------- src/selection.hh | 4 ++-- 8 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 49ef596a..a06d9783 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -518,7 +518,7 @@ void Buffer::do_insert(const BufferCoord& pos, const String& content) } for (auto listener : m_change_listeners) - listener->on_insert(begin, end); + listener->on_insert(*this, begin, end); } void Buffer::do_erase(const BufferCoord& begin, const BufferCoord& end) @@ -543,7 +543,7 @@ void Buffer::do_erase(const BufferCoord& begin, const BufferCoord& end) m_lines[i].start -= length; for (auto listener : m_change_listeners) - listener->on_erase(begin, end); + listener->on_erase(*this, begin, end); } void Buffer::apply_modification(const Modification& modification) diff --git a/src/buffer.hh b/src/buffer.hh index 0f8a9602..08a29aee 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -79,8 +79,8 @@ private: class BufferChangeListener { public: - virtual void on_insert(const BufferCoord& begin, const BufferCoord& end) = 0; - virtual void on_erase(const BufferCoord& begin, const BufferCoord& end) = 0; + virtual void on_insert(const Buffer& buffer, const BufferCoord& begin, const BufferCoord& end) = 0; + virtual void on_erase(const Buffer& buffer, const BufferCoord& begin, const BufferCoord& end) = 0; }; // A Buffer is a in-memory representation of a file diff --git a/src/dynamic_selection_list.cc b/src/dynamic_selection_list.cc index 7ad4d864..d3d3497c 100644 --- a/src/dynamic_selection_list.cc +++ b/src/dynamic_selection_list.cc @@ -34,14 +34,14 @@ void DynamicSelectionList::check_invariant() const #endif } -void DynamicSelectionList::on_insert(const BufferCoord& begin, const BufferCoord& end) +void DynamicSelectionList::on_insert(const Buffer& buffer, const BufferCoord& begin, const BufferCoord& end) { - update_insert(begin, end); + update_insert(buffer, begin, end); } -void DynamicSelectionList::on_erase(const BufferCoord& begin, const BufferCoord& end) +void DynamicSelectionList::on_erase(const Buffer& buffer, const BufferCoord& begin, const BufferCoord& end) { - update_erase(begin, end); + update_erase(buffer, begin, end); } } diff --git a/src/dynamic_selection_list.hh b/src/dynamic_selection_list.hh index c1de00f0..7f8da0f0 100644 --- a/src/dynamic_selection_list.hh +++ b/src/dynamic_selection_list.hh @@ -19,8 +19,8 @@ public: void check_invariant() const; private: - void on_insert(const BufferCoord& begin, const BufferCoord& end) override; - void on_erase(const BufferCoord& begin, const BufferCoord& end) override; + void on_insert(const Buffer& buffer, const BufferCoord& begin, const BufferCoord& end) override; + void on_erase(const Buffer& buffer, const BufferCoord& begin, const BufferCoord& end) override; }; } diff --git a/src/editor.cc b/src/editor.cc index 5ccb7889..b1e227f0 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -364,26 +364,26 @@ public: ModifiedRangesListener(Buffer& buffer) : BufferChangeListener_AutoRegister(buffer) {} - void on_insert(const BufferCoord& begin, const BufferCoord& end) + void on_insert(const Buffer& buffer, const BufferCoord& begin, const BufferCoord& end) { - m_ranges.update_insert(begin, end); + m_ranges.update_insert(buffer, begin, end); auto it = std::upper_bound(m_ranges.begin(), m_ranges.end(), begin, [](const BufferCoord& c, const Selection& sel) - { return c < sel.min().coord(); }); + { return c < sel.min(); }); m_ranges.emplace(it, registry().iterator_at(begin), utf8::previous(registry().iterator_at(end))); } - void on_erase(const BufferCoord& begin, const BufferCoord& end) + void on_erase(const Buffer& buffer, const BufferCoord& begin, const BufferCoord& end) { - m_ranges.update_erase(begin, end); + m_ranges.update_erase(buffer, begin, end); BufferIterator pos{registry(), begin}; - if (pos >= buffer().end()) - pos = utf8::previous(buffer().end()); + if (pos >= buffer.end()) + pos = utf8::previous(buffer.end()); auto it = std::upper_bound(m_ranges.begin(), m_ranges.end(), begin, [](const BufferCoord& c, const Selection& sel) - { return c < sel.min().coord(); }); + { return c < sel.min(); }); m_ranges.emplace(it, pos, pos); } SelectionList& ranges() { return m_ranges; } diff --git a/src/highlighters.cc b/src/highlighters.cc index 699e408b..edd3d7d3 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -384,7 +384,7 @@ private: m_option->get>(); } - void on_insert(const BufferCoord& begin, const BufferCoord& end) override + void on_insert(const Buffer&, const BufferCoord& begin, const BufferCoord& end) override { LineCount new_lines = end.line - begin.line; if (new_lines == 0) @@ -399,7 +399,7 @@ private: m_option->set(lines); } - void on_erase(const BufferCoord& begin, const BufferCoord& end) override + void on_erase(const Buffer&, const BufferCoord& begin, const BufferCoord& end) override { LineCount removed_lines = end.line - begin.line; if (removed_lines == 0) diff --git a/src/selection.cc b/src/selection.cc index 3d8065c3..0a4c4e32 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -18,30 +18,31 @@ namespace { template