1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 20:28:11 +00: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
10 changed files with 59 additions and 90 deletions

View file

@ -13,7 +13,7 @@
namespace JS {
static Syntax::TextStyle style_for_token_type(Gfx::Palette const& palette, TokenType type)
static Gfx::TextAttributes style_for_token_type(Gfx::Palette const& palette, TokenType type)
{
switch (Token::category(type)) {
case TokenCategory::Invalid:
@ -27,9 +27,9 @@ static Syntax::TextStyle style_for_token_type(Gfx::Palette const& palette, Token
case TokenCategory::Operator:
return { palette.syntax_operator() };
case TokenCategory::Keyword:
return { palette.syntax_keyword(), true };
return { palette.syntax_keyword(), {}, true };
case TokenCategory::ControlKeyword:
return { palette.syntax_control_keyword(), true };
return { palette.syntax_control_keyword(), {}, true };
case TokenCategory::Identifier:
return { palette.syntax_identifier() };
default:
@ -79,9 +79,7 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
span.range.set_start(start);
span.range.set_end({ position.line(), position.column() });
auto type = is_trivia ? TokenType::Invalid : token.type();
auto style = style_for_token_type(palette, type);
span.attributes.color = style.color;
span.attributes.bold = style.bold;
span.attributes = style_for_token_type(palette, type);
span.is_skippable = is_trivia;
span.data = static_cast<u64>(type);
spans.append(span);