Add undo system with coalescing logic and comprehensive tests.
- Implemented robust undo system supporting coalescing of text operations (insert, backspace, delete). - Added `UndoSystem` integration into the editor/commands pipeline. - Wrote extensive unit tests for various undo/redo scenarios, including multiline operations, cursor preservation, and history management. - Refactored to ensure consistent cursor behavior during undo/redo actions. - Updated CMake to include new tests.
This commit is contained in:
@@ -122,4 +122,37 @@ TEST (VisualLineMode_CancelWithCtrlG)
|
||||
std::cerr << "Got (len=" << got.size() << ") bytes: " << dump_bytes(got) << "\n";
|
||||
}
|
||||
ASSERT_TRUE(got == exp);
|
||||
}
|
||||
|
||||
|
||||
TEST (Yank_ClearsMarkAndVisualLine)
|
||||
{
|
||||
InstallDefaultCommands();
|
||||
|
||||
Editor ed;
|
||||
ed.SetDimensions(24, 80);
|
||||
|
||||
Buffer b;
|
||||
b.insert_text(0, 0, "foo\nbar\n");
|
||||
b.SetCursor(1, 0);
|
||||
ed.AddBuffer(std::move(b));
|
||||
|
||||
ASSERT_TRUE(ed.CurrentBuffer() != nullptr);
|
||||
Buffer *buf = ed.CurrentBuffer();
|
||||
|
||||
// Seed mark + visual-line highlighting.
|
||||
buf->SetMark(buf->Curx(), buf->Cury());
|
||||
ASSERT_TRUE(buf->MarkSet());
|
||||
|
||||
ASSERT_TRUE(Execute(ed, std::string("visual-line-toggle")));
|
||||
ASSERT_TRUE(Execute(ed, std::string("down"), std::string(), 1));
|
||||
ASSERT_TRUE(buf->VisualLineActive());
|
||||
|
||||
// Yank should clear mark and any highlighting.
|
||||
ed.KillRingClear();
|
||||
ed.KillRingPush("X");
|
||||
ASSERT_TRUE(Execute(ed, std::string("yank")));
|
||||
|
||||
ASSERT_TRUE(!buf->MarkSet());
|
||||
ASSERT_TRUE(!buf->VisualLineActive());
|
||||
}
|
||||
Reference in New Issue
Block a user