1
0
mirror of synced 2024-11-24 07:40:17 +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,22 +549,25 @@ 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) {
if ((std::chrono::steady_clock::now() - m_lastEditorChangeTime) > std::chrono::seconds(1)) {
m_hasUnevaluatedChanges = false;
const auto &code = m_textEditor.GetText();
auto code = m_textEditor.GetText();
EventPatternEditorChanged::post(code);
TaskManager::createBackgroundTask("hex.builtin.task.parsing_pattern"_lang, [this, code, provider](auto &){
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_triggerAutoEvaluate.exchange(false)) {
this->evaluatePattern(m_textEditor.GetText(), provider);