fix bug of undo/redo creating new change operations themselves
This commit is contained in:
parent
3e50e8a3b3
commit
4e03fbc3de
@ -185,14 +185,17 @@ void Buffer::insert_code_point(const Buffer::Iterator & position, uint32_t code_
|
|||||||
{
|
{
|
||||||
bytes += Encoding::encode('\n', m_encoding, &encoded[bytes]);
|
bytes += Encoding::encode('\n', m_encoding, &encoded[bytes]);
|
||||||
}
|
}
|
||||||
insert_data(position.offset(), encoded, bytes);
|
insert_data(position.offset(), encoded, bytes, true);
|
||||||
pop_operation();
|
pop_operation();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::insert_data(size_t offset, const uint8_t data[], size_t length)
|
void Buffer::insert_data(size_t offset, const uint8_t data[], size_t length, bool do_record_change)
|
||||||
{
|
{
|
||||||
m_gap_buffer->insert(offset, data, length);
|
m_gap_buffer->insert(offset, data, length);
|
||||||
record_change(offset, length, true);
|
if (do_record_change)
|
||||||
|
{
|
||||||
|
record_change(offset, length, true);
|
||||||
|
}
|
||||||
warp_iterators_after_insert(offset, length);
|
warp_iterators_after_insert(offset, length);
|
||||||
post_warp_cursors();
|
post_warp_cursors();
|
||||||
}
|
}
|
||||||
@ -202,15 +205,20 @@ void Buffer::erase_code_point(const Buffer::Iterator & position)
|
|||||||
if (position.valid())
|
if (position.valid())
|
||||||
{
|
{
|
||||||
push_operation();
|
push_operation();
|
||||||
erase_data(position.offset(), Encoding::num_bytes_in_code_point(m_encoding, position.address()));
|
erase_data(position.offset(),
|
||||||
|
Encoding::num_bytes_in_code_point(m_encoding, position.address()),
|
||||||
|
true);
|
||||||
pop_operation();
|
pop_operation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::erase_data(size_t offset, size_t length)
|
void Buffer::erase_data(size_t offset, size_t length, bool do_record_change)
|
||||||
{
|
{
|
||||||
warp_iterators_before_delete(offset, length);
|
warp_iterators_before_delete(offset, length);
|
||||||
record_change(offset, length, false);
|
if (do_record_change)
|
||||||
|
{
|
||||||
|
record_change(offset, length, false);
|
||||||
|
}
|
||||||
m_gap_buffer->erase(offset, length);
|
m_gap_buffer->erase(offset, length);
|
||||||
post_warp_cursors();
|
post_warp_cursors();
|
||||||
}
|
}
|
||||||
@ -392,11 +400,14 @@ void Buffer::apply_change_unit(const ChangeUnit & change_unit, bool forward)
|
|||||||
m_change_buffer->compact();
|
m_change_buffer->compact();
|
||||||
insert_data(change_unit.buffer_position,
|
insert_data(change_unit.buffer_position,
|
||||||
m_change_buffer->address(change_unit.change_buffer_offset),
|
m_change_buffer->address(change_unit.change_buffer_offset),
|
||||||
change_unit.length);
|
change_unit.length,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
erase_data(change_unit.buffer_position, change_unit.length);
|
erase_data(change_unit.buffer_position,
|
||||||
|
change_unit.length,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,8 +166,8 @@ protected:
|
|||||||
void save_current_operation();
|
void save_current_operation();
|
||||||
void warp_iterators_after_insert(size_t offset, size_t length);
|
void warp_iterators_after_insert(size_t offset, size_t length);
|
||||||
void warp_iterators_before_delete(size_t offset, size_t length);
|
void warp_iterators_before_delete(size_t offset, size_t length);
|
||||||
void insert_data(size_t offset, const uint8_t data[], size_t length);
|
void insert_data(size_t offset, const uint8_t data[], size_t length, bool do_record_change);
|
||||||
void erase_data(size_t offset, size_t length);
|
void erase_data(size_t offset, size_t length, bool do_record_change);
|
||||||
size_t lines_in_data(size_t offset, size_t length);
|
size_t lines_in_data(size_t offset, size_t length);
|
||||||
void post_warp_cursors();
|
void post_warp_cursors();
|
||||||
void apply_change_operation(const ChangeOperation & change_operation, bool forward);
|
void apply_change_operation(const ChangeOperation & change_operation, bool forward);
|
||||||
|
@ -195,6 +195,10 @@ TEST(BufferTest, allows_undo_and_redo_of_inserts)
|
|||||||
b.redo();
|
b.redo();
|
||||||
EXPECT_EQ(ss("12abc\nd3ef$\nghi\n"), b.get_string());
|
EXPECT_EQ(ss("12abc\nd3ef$\nghi\n"), b.get_string());
|
||||||
EXPECT_EQ(C('d'), **it);
|
EXPECT_EQ(C('d'), **it);
|
||||||
|
|
||||||
|
/* undo/redo do not create new operations */
|
||||||
|
EXPECT_FALSE(b.m_current_change_operation);
|
||||||
|
EXPECT_EQ(3u, b.m_change_operations.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BufferTest, allows_undo_and_redo_of_erases)
|
TEST(BufferTest, allows_undo_and_redo_of_erases)
|
||||||
@ -247,6 +251,10 @@ TEST(BufferTest, allows_undo_and_redo_of_erases)
|
|||||||
b.redo();
|
b.redo();
|
||||||
EXPECT_EQ(ss("bc\ndfghi\n"), b.get_string());
|
EXPECT_EQ(ss("bc\ndfghi\n"), b.get_string());
|
||||||
EXPECT_EQ(C('f'), **it);
|
EXPECT_EQ(C('f'), **it);
|
||||||
|
|
||||||
|
/* undo/redo do not create new operations */
|
||||||
|
EXPECT_FALSE(b.m_current_change_operation);
|
||||||
|
EXPECT_EQ(3u, b.m_change_operations.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BufferTest, erase_chunks_are_coalesced_within_a_change_operation)
|
TEST(BufferTest, erase_chunks_are_coalesced_within_a_change_operation)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user