Buffer: refactor common iterator warping code into warp_iterators()
This commit is contained in:
parent
38a734b5c1
commit
924d005020
@ -183,13 +183,7 @@ void Buffer::insert_code_point(const Buffer::Iterator & position, uint32_t code_
|
|||||||
ssize_t lines = (code_point == '\n') ? 1 : 0;
|
ssize_t lines = (code_point == '\n') ? 1 : 0;
|
||||||
if (adjust_iterators)
|
if (adjust_iterators)
|
||||||
{
|
{
|
||||||
for (auto iterator : m_iterators)
|
warp_iterators(local_position.offset(), bytes, lines, true);
|
||||||
{
|
|
||||||
if (*iterator >= local_position)
|
|
||||||
{
|
|
||||||
iterator->warp(bytes, lines);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pop_operation();
|
pop_operation();
|
||||||
}
|
}
|
||||||
@ -205,17 +199,26 @@ void Buffer::erase_code_point(const Buffer::Iterator & position)
|
|||||||
record_change(local_position.address(), bytes, local_position.offset(), false);
|
record_change(local_position.address(), bytes, local_position.offset(), false);
|
||||||
m_gap_buffer->erase(local_position.offset(), bytes);
|
m_gap_buffer->erase(local_position.offset(), bytes);
|
||||||
ssize_t lines = (code_point == '\n') ? -1 : 0;
|
ssize_t lines = (code_point == '\n') ? -1 : 0;
|
||||||
for (auto iterator : m_iterators)
|
warp_iterators(local_position.offset(), -(ssize_t)bytes, lines, false);
|
||||||
{
|
|
||||||
if (*iterator > local_position)
|
|
||||||
{
|
|
||||||
iterator->warp(-(ssize_t)bytes, lines);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pop_operation();
|
pop_operation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Buffer::warp_iterators(size_t offset, ssize_t offset_adjustment, ssize_t lines_adjustment, bool include_equal)
|
||||||
|
{
|
||||||
|
if (!include_equal)
|
||||||
|
{
|
||||||
|
offset++;
|
||||||
|
}
|
||||||
|
for (auto iterator : m_iterators)
|
||||||
|
{
|
||||||
|
if (iterator->offset() >= offset)
|
||||||
|
{
|
||||||
|
iterator->warp(offset_adjustment, lines_adjustment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Buffer::pop_operation()
|
void Buffer::pop_operation()
|
||||||
{
|
{
|
||||||
if (m_operation_level > 0)
|
if (m_operation_level > 0)
|
||||||
|
@ -144,6 +144,7 @@ protected:
|
|||||||
void load_text_in_buffer(uint8_t * buffer, size_t buffer_size, size_t data_length);
|
void load_text_in_buffer(uint8_t * buffer, size_t buffer_size, size_t data_length);
|
||||||
void record_change(uint8_t data[], size_t length, size_t buffer_position, bool insert);
|
void record_change(uint8_t data[], size_t length, size_t buffer_position, bool insert);
|
||||||
void save_current_operation();
|
void save_current_operation();
|
||||||
|
void warp_iterators(size_t offset, ssize_t offset_adjustment, ssize_t lines_adjustments, bool include_equal);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user