Fix BufferIterator::on_erase and tweak Buffer
This commit is contained in:
parent
9b6b6b6b17
commit
36e4dacdf5
|
@ -152,7 +152,7 @@ void Buffer::end_undo_group()
|
|||
if (m_current_undo_group.empty())
|
||||
return;
|
||||
|
||||
m_history.push_back(m_current_undo_group);
|
||||
m_history.push_back(std::move(m_current_undo_group));
|
||||
m_history_cursor = m_history.end();
|
||||
|
||||
m_current_undo_group.clear();
|
||||
|
@ -277,6 +277,7 @@ void Buffer::insert(const BufferIterator& pos, const String& content)
|
|||
void Buffer::erase(const BufferIterator& pos, BufferSize length)
|
||||
{
|
||||
BufferIterator end = pos + length;
|
||||
assert(end.is_valid());
|
||||
String prefix = m_lines[pos.line()].content.substr(0, pos.column());
|
||||
String suffix = m_lines[end.line()].content.substr(end.column());
|
||||
Line new_line = { m_lines[pos.line()].start, prefix + suffix };
|
||||
|
|
|
@ -32,6 +32,7 @@ inline BufferIterator& BufferIterator::operator=(const BufferIterator& iterator)
|
|||
{
|
||||
m_buffer = iterator.m_buffer;
|
||||
m_coord = iterator.m_coord;
|
||||
assert(is_valid());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -90,18 +91,17 @@ inline void BufferIterator::on_erase(const BufferCoord& begin,
|
|||
if (m_coord < begin)
|
||||
return;
|
||||
|
||||
BufferCoord measure;
|
||||
measure.line = end.line - begin.line;
|
||||
measure.column = end.column - (measure.line == 0 ? begin.column : 0);
|
||||
if (m_coord <= end)
|
||||
m_coord = begin;
|
||||
else
|
||||
{
|
||||
m_coord.line -= measure.line;
|
||||
if (measure.line > 0 and begin.line == m_coord.line)
|
||||
m_coord.column += begin.column;
|
||||
if (end.line == m_coord.line)
|
||||
m_coord.column -= measure.column;
|
||||
{
|
||||
m_coord.line = begin.line;
|
||||
m_coord.column = begin.column + m_coord.column - end.column;
|
||||
}
|
||||
else
|
||||
m_coord.line -= end.line - begin.line;
|
||||
}
|
||||
|
||||
if (is_end())
|
||||
|
|
Loading…
Reference in New Issue
Block a user