impr: Re-parse patterns only when the user stopped typing
This commit is contained in:
parent
0184bf9a7d
commit
0a038fecff
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user