From 67a251ffd560d79e8337fef0aee8d8285d34355e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 12 May 2014 13:59:21 +0100 Subject: [PATCH] Pass a at_end param to BufferChangeListener::on_{insert,erase} --- src/buffer.cc | 8 +++---- src/buffer.hh | 4 ++-- src/dynamic_selection_list.cc | 8 +++---- src/dynamic_selection_list.hh | 4 ++-- src/normal.cc | 8 +++---- src/selection.cc | 40 ++++++++++++++++++++--------------- src/selection.hh | 4 ++-- 7 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index c92f09b1..f4b6782f 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -76,7 +76,7 @@ void Buffer::reload(std::vector lines, time_t fs_timestamp) // use back coord to simulate the persistance of the last end of line // as buffers are expected to never be empty. for (auto listener : m_change_listeners) - listener->on_erase(*this, {0,0}, back_coord()); + listener->on_erase(*this, {0,0}, back_coord(), true); m_changes.push_back({ Change::Erase, {0,0}, back_coord(), true }); @@ -102,7 +102,7 @@ void Buffer::reload(std::vector lines, time_t fs_timestamp) m_changes.push_back({ Change::Insert, {0,0}, back_coord(), true }); for (auto listener : m_change_listeners) - listener->on_insert(*this, {0,0}, back_coord()); + listener->on_insert(*this, {0,0}, back_coord(), true); } String Buffer::display_name() const @@ -523,7 +523,7 @@ ByteCoord Buffer::do_insert(ByteCoord pos, const String& content) m_changes.push_back({ Change::Insert, begin, end, at_end }); for (auto listener : m_change_listeners) - listener->on_insert(*this, begin, end); + listener->on_insert(*this, begin, end, at_end); return begin; } @@ -554,7 +554,7 @@ ByteCoord Buffer::do_erase(ByteCoord begin, ByteCoord end) m_changes.push_back({ Change::Erase, begin, end, is_end(begin) }); for (auto listener : m_change_listeners) - listener->on_erase(*this, begin, end); + listener->on_erase(*this, begin, end, is_end(begin)); return next; } diff --git a/src/buffer.hh b/src/buffer.hh index 89684ce5..f817eef0 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -67,9 +67,9 @@ class BufferChangeListener { public: virtual void on_insert(const Buffer& buffer, - ByteCoord begin, ByteCoord end) = 0; + ByteCoord begin, ByteCoord end, bool at_end) = 0; virtual void on_erase(const Buffer& buffer, - ByteCoord begin, ByteCoord end) = 0; + ByteCoord begin, ByteCoord end, bool at_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 569d7818..2792da30 100644 --- a/src/dynamic_selection_list.cc +++ b/src/dynamic_selection_list.cc @@ -36,14 +36,14 @@ void DynamicSelectionList::check_invariant() const #endif } -void DynamicSelectionList::on_insert(const Buffer& buffer, ByteCoord begin, ByteCoord end) +void DynamicSelectionList::on_insert(const Buffer& buffer, ByteCoord begin, ByteCoord end, bool at_end) { - update_insert(buffer, begin, end); + update_insert(begin, end, at_end); } -void DynamicSelectionList::on_erase(const Buffer& buffer, ByteCoord begin, ByteCoord end) +void DynamicSelectionList::on_erase(const Buffer& buffer, ByteCoord begin, ByteCoord end, bool at_end) { - update_erase(buffer, begin, end); + update_erase(begin, end, at_end); } } diff --git a/src/dynamic_selection_list.hh b/src/dynamic_selection_list.hh index 4bfbd39a..2f408907 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 Buffer& buffer, ByteCoord begin, ByteCoord end) override; - void on_erase(const Buffer& buffer, ByteCoord begin, ByteCoord end) override; + void on_insert(const Buffer& buffer, ByteCoord begin, ByteCoord end, bool at_end) override; + void on_erase(const Buffer& buffer, ByteCoord begin, ByteCoord end, bool at_end) override; }; } diff --git a/src/normal.cc b/src/normal.cc index 062f512c..5016ece9 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1239,18 +1239,18 @@ public: ModifiedRangesListener(Buffer& buffer) : BufferChangeListener_AutoRegister(buffer) {} - void on_insert(const Buffer& buffer, ByteCoord begin, ByteCoord end) + void on_insert(const Buffer& buffer, ByteCoord begin, ByteCoord end, bool at_end) { - m_ranges.update_insert(buffer, begin, end); + m_ranges.update_insert(begin, end, at_end); auto it = std::upper_bound(m_ranges.begin(), m_ranges.end(), begin, [](ByteCoord c, const Selection& sel) { return c < sel.min(); }); m_ranges.insert(it, Selection{ begin, buffer.char_prev(end) }); } - void on_erase(const Buffer& buffer, ByteCoord begin, ByteCoord end) + void on_erase(const Buffer& buffer, ByteCoord begin, ByteCoord end, bool at_end) { - m_ranges.update_erase(buffer, begin, end); + m_ranges.update_erase(begin, end, at_end); auto pos = std::min(begin, buffer.back_coord()); auto it = std::upper_bound(m_ranges.begin(), m_ranges.end(), pos, [](ByteCoord c, const Selection& sel) diff --git a/src/selection.cc b/src/selection.cc index e1627a0c..0049689d 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -18,8 +18,8 @@ namespace { template