From 1b97eaad0b4a6fda9b7a42af2184388b38ce981b Mon Sep 17 00:00:00 2001 From: paxcut Date: Wed, 9 Apr 2025 19:40:15 -0700 Subject: [PATCH 1/2] fix: Incorrect horizontal scrollbar displayed. After the recent changes to scrolling the code uses the longest line in the source code to determine if and how big horizontal scrollbars are needed. Instead of the computationally expensive calculation of the longest line, we let the lexer record it when it generates the token stream. It turns out that the lexer is also getting token streams for the included and imported files which leads to the problem. Instead of letting the lexer do both the recording and the reporting of the longest line in the code we use the preprocessor to intercept the value before the included and imported files are preprocessed. The fix is incomplete unless an upcoming PR to ViewPatterneditor.cpp where the longest line size is sent to the text editor is also included. --- lib/include/pl/core/lexer.hpp | 2 +- lib/include/pl/core/preprocessor.hpp | 5 +++-- lib/source/pl/core/lexer.cpp | 2 ++ lib/source/pl/core/preprocessor.cpp | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/include/pl/core/lexer.hpp b/lib/include/pl/core/lexer.hpp index 0496c294..48f4e288 100644 --- a/lib/include/pl/core/lexer.hpp +++ b/lib/include/pl/core/lexer.hpp @@ -49,7 +49,7 @@ namespace pl::core { std::optional parseInteger(std::string_view literal); Token makeToken(const Token& token, size_t length = 1); - static Token makeTokenAt(const Token& token, Location& location, size_t length = 1); + Token makeTokenAt(const Token& token, Location& location, size_t length = 1); void addToken(const Token& token); bool hasTheLineEnded(const char &ch) { if(ch == '\n') { diff --git a/lib/include/pl/core/preprocessor.hpp b/lib/include/pl/core/preprocessor.hpp index ebbf6c5f..c5cf481d 100644 --- a/lib/include/pl/core/preprocessor.hpp +++ b/lib/include/pl/core/preprocessor.hpp @@ -36,7 +36,8 @@ namespace pl::core { void addStatementHandler(const Token::Keyword &statementType, const api::StatementHandler &handler); void removePragmaHandler(const std::string &pragmaType); void removeDirectiveHandler(const Token::Directive &directiveType); - + size_t getLongestLineLength() const { return m_longestLineLength; } + void setLongestLineLength(size_t length) { m_longestLineLength = length; } void validateOutput(); [[nodiscard]] const std::vector& getExcludedLocations() const { @@ -162,7 +163,7 @@ namespace pl::core { std::vector m_result; std::vector m_output; std::vector m_namespaces; - + size_t m_longestLineLength = 0; api::Source* m_source = nullptr; bool m_onlyIncludeOnce = false; diff --git a/lib/source/pl/core/lexer.cpp b/lib/source/pl/core/lexer.cpp index 4b9c388e..82d5c727 100644 --- a/lib/source/pl/core/lexer.cpp +++ b/lib/source/pl/core/lexer.cpp @@ -458,11 +458,13 @@ namespace pl::core { Token Lexer::makeToken(const Token &token, const size_t length) { auto location = this->location(); location.length = length; + m_longestLineLength = std::max(m_longestLineLength, location.column + location.length); return { token.type, token.value, location }; } Token Lexer::makeTokenAt(const Token &token, Location& location, const size_t length) { location.length = length; + m_longestLineLength = std::max(m_longestLineLength, location.column + location.length); return { token.type, token.value, location }; } diff --git a/lib/source/pl/core/preprocessor.cpp b/lib/source/pl/core/preprocessor.cpp index ced81296..9ca00316 100644 --- a/lib/source/pl/core/preprocessor.cpp +++ b/lib/source/pl/core/preprocessor.cpp @@ -601,7 +601,7 @@ namespace pl::core { this->error(item); return { m_output, collectErrors() }; } - + setLongestLineLength(lexer->getLongestLineLength()); m_token = m_result.begin(); m_initialized = true; while (!eof()) From 92e6e84250c443c183990ce65e05f0484ce64767 Mon Sep 17 00:00:00 2001 From: paxcut Date: Thu, 1 May 2025 12:42:30 -0700 Subject: [PATCH 2/2] Update fmt submodule to the latest version --- external/fmt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/fmt b/external/fmt index 0c9fce2f..12391371 160000 --- a/external/fmt +++ b/external/fmt @@ -1 +1 @@ -Subproject commit 0c9fce2ffefecfdce794e1859584e25877b7b592 +Subproject commit 123913715afeb8a437e6388b4473fcc4753e1c9a