mirror of https://github.com/WerWolv/ImHex.git
ui: Properly clear highlighting cache when switching provider
Fixes #471
This commit is contained in:
parent
97bfb4004b
commit
74ef9ece30
|
@ -30,6 +30,12 @@ namespace hex::plugin::builtin {
|
||||||
u32 m_selectedPatternFile = 0;
|
u32 m_selectedPatternFile = 0;
|
||||||
bool m_runAutomatically = false;
|
bool m_runAutomatically = false;
|
||||||
|
|
||||||
|
bool m_lastEvaluationProcessed = true;
|
||||||
|
bool m_lastEvaluationResult = false;
|
||||||
|
std::optional<pl::PatternLanguageError> m_lastEvaluationError;
|
||||||
|
std::vector<std::pair<pl::LogConsole::Level, std::string>> m_lastEvaluationLog;
|
||||||
|
std::map<std::string, pl::Token::Literal> m_lastEvaluationOutVars;
|
||||||
|
|
||||||
std::atomic<u32> m_runningEvaluators = 0;
|
std::atomic<u32> m_runningEvaluators = 0;
|
||||||
std::atomic<u32> m_runningParsers = 0;
|
std::atomic<u32> m_runningParsers = 0;
|
||||||
|
|
||||||
|
|
|
@ -204,6 +204,7 @@ namespace hex::plugin::builtin {
|
||||||
EventManager::unsubscribe<RequestOpenWindow>(this);
|
EventManager::unsubscribe<RequestOpenWindow>(this);
|
||||||
EventManager::unsubscribe<EventSettingsChanged>(this);
|
EventManager::unsubscribe<EventSettingsChanged>(this);
|
||||||
EventManager::unsubscribe<EventHighlightingChanged>(this);
|
EventManager::unsubscribe<EventHighlightingChanged>(this);
|
||||||
|
EventManager::unsubscribe<EventProviderChanged>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewHexEditor::drawContent() {
|
void ViewHexEditor::drawContent() {
|
||||||
|
@ -962,6 +963,10 @@ namespace hex::plugin::builtin {
|
||||||
EventManager::subscribe<EventHighlightingChanged>(this, [this] {
|
EventManager::subscribe<EventHighlightingChanged>(this, [this] {
|
||||||
this->m_highlights.clear();
|
this->m_highlights.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
EventManager::subscribe<EventProviderChanged>(this, [](auto, auto) {
|
||||||
|
EventManager::post<EventHighlightingChanged>();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewHexEditor::registerShortcuts() {
|
void ViewHexEditor::registerShortcuts() {
|
||||||
|
|
|
@ -352,6 +352,26 @@ namespace hex::plugin::builtin {
|
||||||
View::discardNavigationRequests();
|
View::discardNavigationRequests();
|
||||||
}
|
}
|
||||||
ImGui::End();
|
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<EventHighlightingChanged>();
|
||||||
|
}
|
||||||
|
|
||||||
|
this->m_lastEvaluationProcessed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewPatternEditor::drawConsole(ImVec2 size) {
|
void ViewPatternEditor::drawConsole(ImVec2 size) {
|
||||||
|
@ -657,30 +677,16 @@ namespace hex::plugin::builtin {
|
||||||
auto provider = ImHexApi::Provider::get();
|
auto provider = ImHexApi::Provider::get();
|
||||||
auto &runtime = provider->getPatternLanguageRuntime();
|
auto &runtime = provider->getPatternLanguageRuntime();
|
||||||
|
|
||||||
auto result = runtime.executeString(provider, code, envVars, inVariables);
|
this->m_lastEvaluationResult = runtime.executeString(provider, code, envVars, inVariables);
|
||||||
if (!result) {
|
if (!this->m_lastEvaluationResult) {
|
||||||
auto error = runtime.getError();
|
this->m_lastEvaluationError = 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<EventHighlightingChanged>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->m_lastEvaluationLog = runtime.getConsoleLog();
|
||||||
|
this->m_lastEvaluationOutVars = runtime.getOutVariables();
|
||||||
this->m_runningEvaluators--;
|
this->m_runningEvaluators--;
|
||||||
|
|
||||||
|
this->m_lastEvaluationProcessed = false;
|
||||||
}).detach();
|
}).detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue