summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-05-12 13:59:21 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-05-13 19:01:27 +0100
commit67a251ffd560d79e8337fef0aee8d8285d34355e (patch)
tree852a301689b7612f958cda7728004b59aa47e335 /src
parentddd8f8d392ae059298ffa6175165f6e224a009f9 (diff)
Pass a at_end param to BufferChangeListener::on_{insert,erase}
Diffstat (limited to 'src')
-rw-r--r--src/buffer.cc8
-rw-r--r--src/buffer.hh4
-rw-r--r--src/dynamic_selection_list.cc8
-rw-r--r--src/dynamic_selection_list.hh4
-rw-r--r--src/normal.cc8
-rw-r--r--src/selection.cc40
-rw-r--r--src/selection.hh4
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<String> 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<String> 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<template <bool, bool> class UpdateFunc>
-void on_buffer_change(const Buffer& buffer, SelectionList& sels,
- ByteCoord begin, ByteCoord end, LineCount end_line)
+void on_buffer_change(SelectionList& sels,
+ ByteCoord begin, ByteCoord end, bool at_end, LineCount end_line)
{
auto update_beg = std::lower_bound(sels.begin(), sels.end(), begin,
[](const Selection& s, ByteCoord c)
@@ -31,20 +31,20 @@ void on_buffer_change(const Buffer& buffer, SelectionList& sels,
if (update_beg != update_only_line_beg)
{
// for the first one, we are not sure if min < begin
- UpdateFunc<false, false>{}(buffer, update_beg->anchor(), begin, end);
- UpdateFunc<false, false>{}(buffer, update_beg->cursor(), begin, end);
+ UpdateFunc<false, false>{}(update_beg->anchor(), begin, end, at_end);
+ UpdateFunc<false, false>{}(update_beg->cursor(), begin, end, at_end);
}
for (auto it = update_beg+1; it < update_only_line_beg; ++it)
{
- UpdateFunc<false, true>{}(buffer, it->anchor(), begin, end);
- UpdateFunc<false, true>{}(buffer, it->cursor(), begin, end);
+ UpdateFunc<false, true>{}(it->anchor(), begin, end, at_end);
+ UpdateFunc<false, true>{}(it->cursor(), begin, end, at_end);
}
if (end.line > begin.line)
{
for (auto it = update_only_line_beg; it != sels.end(); ++it)
{
- UpdateFunc<true, true>{}(buffer, it->anchor(), begin, end);
- UpdateFunc<true, true>{}(buffer, it->cursor(), begin, end);
+ UpdateFunc<true, true>{}(it->anchor(), begin, end, at_end);
+ UpdateFunc<true, true>{}(it->cursor(), begin, end, at_end);
}
}
}
@@ -52,8 +52,8 @@ void on_buffer_change(const Buffer& buffer, SelectionList& sels,
template<bool assume_different_line, bool assume_greater_than_begin>
struct UpdateInsert
{
- void operator()(const Buffer& buffer, ByteCoord& coord,
- ByteCoord begin, ByteCoord end) const
+ void operator()(ByteCoord& coord, ByteCoord begin, ByteCoord end,
+ bool at_end) const
{
if (assume_different_line)
kak_assert(begin.line < coord.line);
@@ -69,15 +69,21 @@ struct UpdateInsert
template<bool assume_different_line, bool assume_greater_than_begin>
struct UpdateErase
{
- void operator()(const Buffer& buffer, ByteCoord& coord,
- ByteCoord begin, ByteCoord end) const
+ void operator()(ByteCoord& coord, ByteCoord begin, ByteCoord end,
+ bool at_end) const
{
if (not assume_greater_than_begin and coord < begin)
return;
if (assume_different_line)
kak_assert(end.line < coord.line);
if (not assume_different_line and coord <= end)
- coord = buffer.clamp(begin);
+ {
+ if (not at_end)
+ coord = begin;
+ else
+ coord = begin.column ? ByteCoord{begin.line, begin.column-1}
+ : ByteCoord{begin.line - 1};
+ }
else
{
if (not assume_different_line and end.line == coord.line)
@@ -93,14 +99,14 @@ struct UpdateErase
}
-void SelectionList::update_insert(const Buffer& buffer, ByteCoord begin, ByteCoord end)
+void SelectionList::update_insert(ByteCoord begin, ByteCoord end, bool at_end)
{
- on_buffer_change<UpdateInsert>(buffer, *this, begin, end, begin.line);
+ on_buffer_change<UpdateInsert>(*this, begin, end, at_end, begin.line);
}
-void SelectionList::update_erase(const Buffer& buffer, ByteCoord begin, ByteCoord end)
+void SelectionList::update_erase(ByteCoord begin, ByteCoord end, bool at_end)
{
- on_buffer_change<UpdateErase>(buffer, *this, begin, end, end.line);
+ on_buffer_change<UpdateErase>(*this, begin, end, at_end, end.line);
}
void SelectionList::check_invariant() const
diff --git a/src/selection.hh b/src/selection.hh
index 61e1cc54..016ce5f5 100644
--- a/src/selection.hh
+++ b/src/selection.hh
@@ -61,8 +61,8 @@ struct SelectionList
SelectionList(ByteCoord c) : m_selections{Selection{c,c}} {}
SelectionList(Selection s) : m_selections{s} {}
- void update_insert(const Buffer& buffer, ByteCoord begin, ByteCoord end);
- void update_erase(const Buffer& buffer, ByteCoord begin, ByteCoord end);
+ void update_insert(ByteCoord begin, ByteCoord end, bool at_end);
+ void update_erase(ByteCoord begin, ByteCoord end, bool at_end);
void check_invariant() const;