mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
feat: Implement better and more complete undo/redo stack (#1433)
This PR aims to implement a more complete undo/redo stack that, unlike the old one, also supports undoing insertions, deletions and resize operations
This commit is contained in:
@@ -165,8 +165,9 @@ namespace hex::plugin::builtin::ui {
|
||||
|
||||
if (this->m_editingBytes.size() < size) {
|
||||
this->m_editingBytes.resize(size);
|
||||
std::memcpy(this->m_editingBytes.data(), data, size);
|
||||
}
|
||||
|
||||
std::memcpy(this->m_editingBytes.data(), data, size);
|
||||
}
|
||||
|
||||
if (this->m_editingAddress != address || this->m_editingCellType != cellType) {
|
||||
@@ -217,9 +218,23 @@ namespace hex::plugin::builtin::ui {
|
||||
}
|
||||
|
||||
if (shouldExitEditingMode || this->m_shouldModifyValue) {
|
||||
this->m_provider->write(*this->m_editingAddress, this->m_editingBytes.data(), this->m_editingBytes.size());
|
||||
{
|
||||
std::vector<u8> oldData(this->m_editingBytes.size());
|
||||
this->m_provider->read(*this->m_editingAddress, oldData.data(), oldData.size());
|
||||
|
||||
if (!this->m_selectionChanged && !ImGui::IsMouseDown(ImGuiMouseButton_Left) && !ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
||||
size_t writtenBytes = 0;
|
||||
for (size_t i = 0; i < this->m_editingBytes.size(); i += 1) {
|
||||
if (this->m_editingBytes[i] != oldData[i]) {
|
||||
this->m_provider->write(*this->m_editingAddress, &this->m_editingBytes[i], 1);
|
||||
writtenBytes += 1;
|
||||
}
|
||||
}
|
||||
|
||||
this->m_provider->getUndoStack().groupOperations(writtenBytes, "hex.builtin.undo_operation.modification");
|
||||
}
|
||||
|
||||
|
||||
if (!this->m_selectionChanged && !ImGui::IsMouseDown(ImGuiMouseButton_Left) && !ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !ImGui::IsKeyDown(ImGuiKey_Escape)) {
|
||||
auto nextEditingAddress = *this->m_editingAddress + this->m_currDataVisualizer->getBytesPerCell();
|
||||
this->setSelection(nextEditingAddress, nextEditingAddress);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user