diff --git a/plugins/builtin/include/content/views/view_pattern_editor.hpp b/plugins/builtin/include/content/views/view_pattern_editor.hpp index 78a7bef07..3f238d117 100644 --- a/plugins/builtin/include/content/views/view_pattern_editor.hpp +++ b/plugins/builtin/include/content/views/view_pattern_editor.hpp @@ -30,6 +30,12 @@ namespace hex::plugin::builtin { u32 m_selectedPatternFile = 0; bool m_runAutomatically = false; + bool m_lastEvaluationProcessed = true; + bool m_lastEvaluationResult = false; + std::optional m_lastEvaluationError; + std::vector> m_lastEvaluationLog; + std::map m_lastEvaluationOutVars; + std::atomic m_runningEvaluators = 0; std::atomic m_runningParsers = 0; diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 344d9b2a0..9fbe401e5 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -204,6 +204,7 @@ namespace hex::plugin::builtin { EventManager::unsubscribe(this); EventManager::unsubscribe(this); EventManager::unsubscribe(this); + EventManager::unsubscribe(this); } void ViewHexEditor::drawContent() { @@ -962,6 +963,10 @@ namespace hex::plugin::builtin { EventManager::subscribe(this, [this] { this->m_highlights.clear(); }); + + EventManager::subscribe(this, [](auto, auto) { + EventManager::post(); + }); } void ViewHexEditor::registerShortcuts() { diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 53f507594..28c1eb6b7 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -352,6 +352,26 @@ namespace hex::plugin::builtin { View::discardNavigationRequests(); } ImGui::End(); + + if (!this->m_lastEvaluationProcessed) { + this->m_console = this->m_lastEvaluationLog; + + if (!this->m_lastEvaluationResult) { + TextEditor::ErrorMarkers errorMarkers = { + {this->m_lastEvaluationError->getLineNumber(), this->m_lastEvaluationError->what()} + }; + this->m_textEditor.SetErrorMarkers(errorMarkers); + } else { + for (auto &[name, variable] : this->m_patternVariables) { + if (variable.outVariable && this->m_lastEvaluationOutVars.contains(name)) + variable.value = this->m_lastEvaluationOutVars.at(name); + } + + EventManager::post(); + } + + this->m_lastEvaluationProcessed = true; + } } void ViewPatternEditor::drawConsole(ImVec2 size) { @@ -657,30 +677,16 @@ namespace hex::plugin::builtin { auto provider = ImHexApi::Provider::get(); auto &runtime = provider->getPatternLanguageRuntime(); - auto result = runtime.executeString(provider, code, envVars, inVariables); - if (!result) { - auto error = runtime.getError(); - if (error) { - TextEditor::ErrorMarkers errorMarkers = { - {error->getLineNumber(), error->what()} - }; - this->m_textEditor.SetErrorMarkers(errorMarkers); - } - } - - this->m_console = runtime.getConsoleLog(); - - auto outVariables = runtime.getOutVariables(); - for (auto &[name, variable] : this->m_patternVariables) { - if (variable.outVariable && outVariables.contains(name)) - variable.value = outVariables.at(name); - } - - if (result) { - EventManager::post(); + this->m_lastEvaluationResult = runtime.executeString(provider, code, envVars, inVariables); + if (!this->m_lastEvaluationResult) { + this->m_lastEvaluationError = runtime.getError(); } + this->m_lastEvaluationLog = runtime.getConsoleLog(); + this->m_lastEvaluationOutVars = runtime.getOutVariables(); this->m_runningEvaluators--; + + this->m_lastEvaluationProcessed = false; }).detach(); }