Buffer: refactor to remove do_{insert,erase} methods
This commit is contained in:
parent
08ba791ff4
commit
dc642f8afa
|
@ -46,18 +46,6 @@ void Buffer::insert(const BufferIterator& position, const BufferString& string)
|
||||||
append_modification(BufferModification(BufferModification::Insert, position, string));
|
append_modification(BufferModification(BufferModification::Insert, position, string));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::do_erase(const BufferIterator& begin, const BufferIterator& end)
|
|
||||||
{
|
|
||||||
m_content.erase(begin.m_position, end - begin);
|
|
||||||
compute_lines();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Buffer::do_insert(const BufferIterator& position, const BufferString& string)
|
|
||||||
{
|
|
||||||
m_content.insert(position.m_position, string);
|
|
||||||
compute_lines();
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferIterator Buffer::iterator_at(const BufferCoord& line_and_column) const
|
BufferIterator Buffer::iterator_at(const BufferCoord& line_and_column) const
|
||||||
{
|
{
|
||||||
if (m_lines.empty())
|
if (m_lines.empty())
|
||||||
|
@ -207,19 +195,21 @@ void Buffer::apply_modification(const BufferModification& modification)
|
||||||
switch (modification.type)
|
switch (modification.type)
|
||||||
{
|
{
|
||||||
case BufferModification::Insert:
|
case BufferModification::Insert:
|
||||||
do_insert(modification.position, modification.content);
|
m_content.insert(modification.position.m_position,
|
||||||
|
modification.content);
|
||||||
break;
|
break;
|
||||||
case BufferModification::Erase:
|
case BufferModification::Erase:
|
||||||
{
|
{
|
||||||
BufferIterator begin = modification.position;
|
size_t size = modification.content.size();
|
||||||
BufferIterator end = begin + modification.content.size();
|
assert(string(modification.position, modification.position + size)
|
||||||
assert(string(begin, end) == modification.content);
|
== modification.content);
|
||||||
do_erase(begin, end);
|
m_content.erase(modification.position.m_position, size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
compute_lines();
|
||||||
for (auto listener : m_modification_listeners)
|
for (auto listener : m_modification_listeners)
|
||||||
listener->on_modification(modification);
|
listener->on_modification(modification);
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,12 +152,6 @@ public:
|
||||||
private:
|
private:
|
||||||
BufferChar at(BufferPos position) const;
|
BufferChar at(BufferPos position) const;
|
||||||
|
|
||||||
void do_erase(const BufferIterator& begin,
|
|
||||||
const BufferIterator& end);
|
|
||||||
|
|
||||||
void do_insert(const BufferIterator& position,
|
|
||||||
const BufferString& string);
|
|
||||||
|
|
||||||
friend class BufferIterator;
|
friend class BufferIterator;
|
||||||
|
|
||||||
std::vector<BufferPos> m_lines;
|
std::vector<BufferPos> m_lines;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user