1
0
mirror of synced 2024-11-12 02:00:52 +01:00

impr: Re-parse patterns only when the user stopped typing

This commit is contained in:
WerWolv 2024-08-03 17:00:23 +02:00
parent 0184bf9a7d
commit 0a038fecff
2 changed files with 12 additions and 8 deletions

View File

@ -190,6 +190,7 @@ namespace hex::plugin::builtin {
std::atomic<u32> m_runningParsers = 0;
bool m_hasUnevaluatedChanges = false;
std::chrono::time_point<std::chrono::steady_clock> m_lastEditorChangeTime;
TextEditor m_textEditor, m_consoleEditor;
std::atomic<bool> m_consoleNeedsUpdate = false;

View File

@ -549,21 +549,24 @@ namespace hex::plugin::builtin {
if (m_textEditor.IsTextChanged()) {
m_hasUnevaluatedChanges = true;
m_lastEditorChangeTime = std::chrono::steady_clock::now();
ImHexApi::Provider::markDirty();
}
if (m_hasUnevaluatedChanges && m_runningEvaluators == 0 && m_runningParsers == 0) {
m_hasUnevaluatedChanges = false;
if ((std::chrono::steady_clock::now() - m_lastEditorChangeTime) > std::chrono::seconds(1)) {
m_hasUnevaluatedChanges = false;
const auto &code = m_textEditor.GetText();
EventPatternEditorChanged::post(code);
auto code = m_textEditor.GetText();
EventPatternEditorChanged::post(code);
TaskManager::createBackgroundTask("hex.builtin.task.parsing_pattern"_lang, [this, code, provider](auto &){
this->parsePattern(code, provider);
TaskManager::createBackgroundTask("hex.builtin.task.parsing_pattern"_lang, [this, code = std::move(code), provider](auto &){
this->parsePattern(code, provider);
if (m_runAutomatically)
m_triggerAutoEvaluate = true;
});
if (m_runAutomatically)
m_triggerAutoEvaluate = true;
});
}
}
if (m_triggerAutoEvaluate.exchange(false)) {