From 4dcd26a21ff7e7e134226541bd531047a4ded421 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 17 Jun 2022 10:16:58 +0200 Subject: [PATCH] fix: Editing value not being updated correctly when moving to next hex cell Fixes #538 --- .../include/content/views/view_hex_editor.hpp | 1 + .../source/content/views/view_hex_editor.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/builtin/include/content/views/view_hex_editor.hpp b/plugins/builtin/include/content/views/view_hex_editor.hpp index a6a16c667..380885339 100644 --- a/plugins/builtin/include/content/views/view_hex_editor.hpp +++ b/plugins/builtin/include/content/views/view_hex_editor.hpp @@ -127,6 +127,7 @@ namespace hex::plugin::builtin { std::optional m_editingAddress; bool m_shouldModifyValue = false; bool m_enteredEditingMode = false; + bool m_shouldUpdateEditingValue = false; std::vector m_editingBytes; color_t m_selectionColor = 0x00; diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 09a5318cb..6539aefd2 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -463,6 +463,13 @@ namespace hex::plugin::builtin { void ViewHexEditor::drawCell(u64 address, u8 *data, size_t size, bool hovered) { auto provider = ImHexApi::Provider::get(); + if (this->m_shouldUpdateEditingValue) { + this->m_shouldUpdateEditingValue = false; + + this->m_editingBytes.resize(size); + std::memcpy(this->m_editingBytes.data(), data, size); + } + if (this->m_editingAddress != address) { this->m_currDataVisualizer->draw(address, data, size, this->m_upperCaseHex); @@ -472,9 +479,7 @@ namespace hex::plugin::builtin { this->m_editingAddress = address; this->m_shouldModifyValue = false; this->m_enteredEditingMode = true; - - this->m_editingBytes.resize(size); - std::memcpy(this->m_editingBytes.data(), data, size); + this->m_shouldUpdateEditingValue = true; } } } @@ -498,10 +503,8 @@ namespace hex::plugin::builtin { this->m_editingAddress = std::nullopt; } - this->m_editingBytes.resize(size); - std::memcpy(this->m_editingBytes.data(), data, size); - this->m_shouldModifyValue = false; + this->m_shouldUpdateEditingValue = true; } this->m_enteredEditingMode = false;