From ec2f0fc8eb748db86a89c5f65c114459505c3654 Mon Sep 17 00:00:00 2001 From: Max Wipfli Date: Fri, 4 Jun 2021 21:12:19 +0200 Subject: [PATCH] LibCpp: Fix off-by-one error in SyntaxHighlighter This changes the C++ SyntaxHighlighter to conform to the now-fixed rendering of syntax highlighting spans in GUI::TextEditor. Contrary to other syntax highlighters, for this one the change has been made to the SyntaxHighlighter rather than the Lexer. This is due to the fact that the Parser also uses the same Lexer. I'm soure there is some more elegant way to do this, but this patch at least unbreaks the C++ syntax highlighting. --- Userland/Libraries/LibCpp/SyntaxHighlighter.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibCpp/SyntaxHighlighter.cpp b/Userland/Libraries/LibCpp/SyntaxHighlighter.cpp index aae1e81bc6a..563fe1db764 100644 --- a/Userland/Libraries/LibCpp/SyntaxHighlighter.cpp +++ b/Userland/Libraries/LibCpp/SyntaxHighlighter.cpp @@ -63,10 +63,11 @@ void SyntaxHighlighter::rehighlight(Palette const& palette) Vector spans; for (auto& token : tokens) { - dbgln_if(SYNTAX_HIGHLIGHTING_DEBUG, "{} @ {}:{} - {}:{}", token.type_as_string(), token.start().line, token.start().column, token.end().line, token.end().column); + // FIXME: The +1 for the token end column is a quick hack due to not wanting to modify the lexer (which is also used by the parser). Maybe there's a better way to do this. + dbgln_if(SYNTAX_HIGHLIGHTING_DEBUG, "{} @ {}:{} - {}:{}", token.type_as_string(), token.start().line, token.start().column, token.end().line, token.end().column + 1); GUI::TextDocumentSpan span; span.range.set_start({ token.start().line, token.start().column }); - span.range.set_end({ token.end().line, token.end().column }); + span.range.set_end({ token.end().line, token.end().column + 1 }); auto style = style_for_token_type(palette, token.type()); span.attributes.color = style.color; span.attributes.bold = style.bold;