diff --git a/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp b/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp index 88a6088ae..0ff8c5532 100644 --- a/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp +++ b/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp @@ -807,16 +807,17 @@ namespace hex::pl { std::optional highlightBytes(size_t offset) override{ auto entry = this->m_template->clone(); + ON_SCOPE_EXIT { delete entry; }; - for (u64 address = this->getOffset(); address < this->getOffset() + this->getSize(); address += this->m_template->getSize()) { - entry->setOffset(address); - if (auto color = entry->highlightBytes(offset); color.has_value()) - return color.value(); - } + if (offset < this->getOffset() || offset >= this->getOffset() + this->getSize()) + return { }; - delete entry; - - return { }; + auto index = (offset - this->getOffset()) / this->m_template->getSize(); + entry->setOffset(this->getOffset() + this->m_template->getSize() * index); + if (auto color = entry->highlightBytes(offset); color.has_value()) + return color.value(); + else + return { }; } std::map getHighlightedAddresses() override { diff --git a/source/views/view_pattern_editor.cpp b/source/views/view_pattern_editor.cpp index 83395cea9..dd43f0531 100644 --- a/source/views/view_pattern_editor.cpp +++ b/source/views/view_pattern_editor.cpp @@ -341,9 +341,9 @@ namespace hex { void ViewPatternEditor::parsePattern(char *buffer) { this->m_evaluatorRunning = true; - this->clearPatternData(); this->m_textEditor.SetErrorMarkers({ }); this->m_console.clear(); + this->clearPatternData(); EventManager::post(); std::thread([this, buffer = std::string(buffer)] { @@ -358,9 +358,9 @@ namespace hex { if (result.has_value()) { SharedData::patternData = std::move(result.value()); - View::doLater([]{ + //View::doLater([]{ EventManager::post(); - }); + //}); } this->m_evaluatorRunning = false;