1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 02:13:56 +09:00

LibSyntax+Libraries: Replace TextStyle with Gfx::TextAttributes

Rather than creating a TextStyle struct, and then copying its fields
over to a TextAttributes, let's just create a TextAttributes to start
with. This also simplifies the syntax highlighting code by letting us
define underlines along with the other text styling.
This commit is contained in:
Sam Atkins 2023-03-15 12:49:17 +00:00 committed by Andreas Kling
parent 6d8f046fd0
commit 406a7ea577
Notes: sideshowbarker 2024-07-17 02:08:15 +09:00
10 changed files with 59 additions and 90 deletions

View file

@ -10,7 +10,7 @@
namespace CMake {
static Syntax::TextStyle style_for_token_type(Gfx::Palette const& palette, Token::Type type)
static Gfx::TextAttributes style_for_token_type(Gfx::Palette const& palette, Token::Type type)
{
switch (type) {
case Token::Type::BracketComment:
@ -30,7 +30,7 @@ static Syntax::TextStyle style_for_token_type(Gfx::Palette const& palette, Token
case Token::Type::UnquotedArgument:
return { palette.syntax_parameter() };
case Token::Type::Garbage:
return { palette.red() };
return { palette.red(), {}, false, Gfx::TextAttributes::UnderlineStyle::Wavy, palette.red() };
case Token::Type::VariableReference:
// This is a bit arbitrary, since we don't have a color specifically for this.
return { palette.syntax_preprocessor_value() };
@ -66,13 +66,7 @@ void SyntaxHighlighter::rehighlight(Gfx::Palette const& palette)
if (!span.range.is_valid())
return;
auto style = style_for_token_type(palette, type);
span.attributes.color = style.color;
span.attributes.bold = style.bold;
if (type == Token::Type::Garbage) {
span.attributes.underline_color = palette.red();
span.attributes.underline_style = Gfx::TextAttributes::UnderlineStyle::Wavy;
}
span.attributes = style_for_token_type(palette, type);
span.is_skippable = false;
span.data = static_cast<u64>(type);
spans.append(move(span));