Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delay for autoeval while editing #1387

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugins/builtin/include/content/views/view_pattern_editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ namespace hex::plugin::builtin {
std::atomic<bool> m_resetDebuggerVariables;
int m_debuggerScopeIndex = 0;

std::chrono::steady_clock::time_point m_lastEditTime;

private:
void drawConsole(ImVec2 size);
void drawEnvVars(ImVec2 size, std::list<EnvVar> &envVars);
Expand Down
23 changes: 14 additions & 9 deletions plugins/builtin/source/content/views/view_pattern_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,25 @@ namespace hex::plugin::builtin {
if (this->m_textEditor.IsTextChanged()) {
this->m_hasUnevaluatedChanges = true;
ImHexApi::Provider::markDirty();
this->m_lastEditTime = std::chrono::steady_clock::now();
}

if (this->m_hasUnevaluatedChanges && this->m_runningEvaluators == 0 && this->m_runningParsers == 0) {
this->m_hasUnevaluatedChanges = false;
auto now = std::chrono::steady_clock::now();
auto timeSinceLastEdit = std::chrono::duration_cast<std::chrono::milliseconds>(now - this->m_lastEditTime).count();
if (timeSinceLastEdit > 500) {
this->m_hasUnevaluatedChanges = false;

auto code = this->m_textEditor.GetText();
EventManager::post<EventPatternEditorChanged>(code);
auto code = this->m_textEditor.GetText();
EventManager::post<EventPatternEditorChanged>(code);

TaskManager::createBackgroundTask("Pattern Parsing", [this, code, provider](auto &){
this->parsePattern(code, provider);
TaskManager::createBackgroundTask("Pattern Parsing", [this, code, provider](auto &){
this->parsePattern(code, provider);

if (this->m_runAutomatically)
this->m_triggerAutoEvaluate = true;
});
if (this->m_runAutomatically)
this->m_triggerAutoEvaluate = true;
});
}
}

if (this->m_triggerAutoEvaluate.exchange(false)) {
Expand Down Expand Up @@ -1340,4 +1345,4 @@ namespace hex::plugin::builtin {
});
}

}
}