From 90a576c3c704ec8442b6b80979c86f42cf5b1d84 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 14 Jun 2023 10:35:23 +0200 Subject: [PATCH] fix: Highlighting and updating of the new console not working well --- lib/external/imgui/source/TextEditor.cpp | 4 ++-- .../include/content/views/view_pattern_editor.hpp | 1 + .../source/content/views/view_pattern_editor.cpp | 15 ++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/external/imgui/source/TextEditor.cpp b/lib/external/imgui/source/TextEditor.cpp index 42be73cfe..1b0cc38b8 100644 --- a/lib/external/imgui/source/TextEditor.cpp +++ b/lib/external/imgui/source/TextEditor.cpp @@ -2046,11 +2046,11 @@ void TextEditor::ColorizeInternal() { auto &startStr = mLanguageDefinition.mCommentStart; auto &singleStartStr = mLanguageDefinition.mSingleLineComment; - if (singleStartStr.size() > 0 && + if (!singleStartStr.empty() && currentIndex + singleStartStr.size() <= line.size() && equals(singleStartStr.begin(), singleStartStr.end(), from, from + singleStartStr.size(), pred)) { withinSingleLineComment = true; - } else if (!withinSingleLineComment && currentIndex + startStr.size() <= line.size() && + } else if (!startStr.empty() && !withinSingleLineComment && currentIndex + startStr.size() <= line.size() && equals(startStr.begin(), startStr.end(), from, from + startStr.size(), pred)) { commentStartLine = currentLine; commentStartIndex = currentIndex; diff --git a/plugins/builtin/include/content/views/view_pattern_editor.hpp b/plugins/builtin/include/content/views/view_pattern_editor.hpp index d388e7f16..570cf3943 100644 --- a/plugins/builtin/include/content/views/view_pattern_editor.hpp +++ b/plugins/builtin/include/content/views/view_pattern_editor.hpp @@ -140,6 +140,7 @@ namespace hex::plugin::builtin { bool m_hasUnevaluatedChanges = false; TextEditor m_textEditor, m_consoleEditor; + std::atomic m_consoleNeedsUpdate = false; std::atomic m_dangerousFunctionCalled = false; std::atomic m_dangerousFunctionsAllowed = DangerousFunctionPerms::Ask; diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 4d608d38a..e8c71158c 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -112,9 +112,9 @@ namespace hex::plugin::builtin { langDef.mName = "Console Log"; langDef.mCaseSensitive = false; langDef.mAutoIndentation = false; - langDef.mCommentStart = "\x01"; - langDef.mCommentEnd = "\x01"; - langDef.mSingleLineComment = "\x01"; + langDef.mCommentStart = ""; + langDef.mCommentEnd = ""; + langDef.mSingleLineComment = ""; initialized = true; } @@ -298,12 +298,10 @@ namespace hex::plugin::builtin { } void ViewPatternEditor::drawConsole(ImVec2 size) { - { + if (this->m_consoleNeedsUpdate) { std::scoped_lock lock(this->m_logMutex); - if (this->m_consoleEditor.GetTotalLines() == 1 || size_t(this->m_consoleEditor.GetTotalLines()) != this->m_console->size()) { - this->m_consoleEditor.SetTextLines(*this->m_console); - } + this->m_consoleEditor.SetTextLines(*this->m_console); } this->m_consoleEditor.Render("##console", size, true); @@ -866,6 +864,7 @@ namespace hex::plugin::builtin { this->m_textEditor.SetErrorMarkers({}); this->m_console->clear(); + this->m_consoleNeedsUpdate = true; this->m_sectionWindowDrawer.clear(); @@ -920,6 +919,7 @@ namespace hex::plugin::builtin { } this->m_console->emplace_back(line); + this->m_consoleNeedsUpdate = true; } }); @@ -935,6 +935,7 @@ namespace hex::plugin::builtin { this->m_console->emplace_back( hex::format("I: Evaluation took {}", runtime.getLastRunningTime()) ); + this->m_consoleNeedsUpdate = true; };