Add ReflowUndo tests and integrate InsertRow undo support

- Added `test_reflow_undo.cc` to validate undo/redo workflows for reflow operations.
- Introduced `UndoType::InsertRow` in `UndoSystem` for tracking row insertion changes in undo history.
- Updated `UndoNode.h` and `UndoSystem.cc` to support row insertion as a standalone undo step.
- Enhanced reflow paragraph functionality to properly record undo/redo actions for both row deletion and insertion.
- Enabled legacy/extended undo tests in `test_undo.cc` for comprehensive validation.
- Updated `CMakeLists.txt` to include new test file in the build target.
This commit is contained in:
2026-02-26 13:21:07 -08:00
parent bc3433e988
commit 27dcb41857
6 changed files with 276 additions and 15 deletions

View File

@@ -4675,7 +4675,14 @@ cmd_reflow_paragraph(CommandContext &ctx)
new_lines.push_back("");
// Replace paragraph lines via PieceTable-backed operations
UndoSystem *u = buf->Undo();
for (std::size_t i = para_end; i + 1 > para_start; --i) {
if (u) {
buf->SetCursor(0, i);
u->Begin(UndoType::DeleteRow);
u->Append(static_cast<std::string>(buf->Rows()[i]));
u->commit();
}
buf->delete_row(static_cast<int>(i));
if (i == 0)
break; // prevent wrap on size_t
@@ -4684,6 +4691,12 @@ cmd_reflow_paragraph(CommandContext &ctx)
std::size_t insert_y = para_start;
for (const auto &ln: new_lines) {
buf->insert_row(static_cast<int>(insert_y), std::string_view(ln));
if (u) {
buf->SetCursor(0, insert_y);
u->Begin(UndoType::InsertRow);
u->Append(std::string_view(ln));
u->commit();
}
insert_y += 1;
}