Skip to content

Commit

Permalink
Merge branch 'WerWolv:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jumanji144 committed Aug 3, 2024
2 parents 294668b + e726fce commit 6a70396
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/external/pattern_language
7 changes: 5 additions & 2 deletions lib/libimhex/source/api/imhex_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,11 @@ namespace hex {
}

void markDirty() {
get()->markDirty();
EventProviderDirtied::post(get());
const auto provider = get();
if (!provider->isDirty()) {
provider->markDirty();
EventProviderDirtied::post(provider);
}
}

void resetDirty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 11 additions & 8 deletions plugins/builtin/source/content/views/view_pattern_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 6a70396

Please sign in to comment.