diff --git a/plugins/builtin/include/content/views/view_pattern_editor.hpp b/plugins/builtin/include/content/views/view_pattern_editor.hpp index 9044b158c..369dd7722 100644 --- a/plugins/builtin/include/content/views/view_pattern_editor.hpp +++ b/plugins/builtin/include/content/views/view_pattern_editor.hpp @@ -190,6 +190,7 @@ namespace hex::plugin::builtin { std::atomic m_runningParsers = 0; bool m_hasUnevaluatedChanges = false; + std::chrono::time_point m_lastEditorChangeTime; TextEditor m_textEditor, m_consoleEditor; std::atomic m_consoleNeedsUpdate = false; diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 71f0b149a..cbfa7464d 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -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)) {