1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:47:45 +00:00

LibGfx+Userland: Make TextAttributes::underline_style optional

Rather than having a style AND a field saying whether to use the style,
just make the style Optional.
This commit is contained in:
Sam Atkins 2023-03-15 12:35:00 +00:00 committed by Andreas Kling
parent 609b616085
commit 6d8f046fd0
10 changed files with 16 additions and 19 deletions

View file

@ -54,7 +54,6 @@ void SyntaxHighlighter::rehighlight(Gfx::Palette const& palette)
span.attributes.color = style.color;
span.attributes.bold = style.bold;
if (type == Token::Type::Garbage) {
span.attributes.underline = true;
span.attributes.underline_color = palette.red();
span.attributes.underline_style = Gfx::TextAttributes::UnderlineStyle::Wavy;
}

View file

@ -70,7 +70,6 @@ void SyntaxHighlighter::rehighlight(Gfx::Palette const& palette)
span.attributes.color = style.color;
span.attributes.bold = style.bold;
if (type == Token::Type::Garbage) {
span.attributes.underline = true;
span.attributes.underline_color = palette.red();
span.attributes.underline_style = Gfx::TextAttributes::UnderlineStyle::Wavy;
}

View file

@ -1391,9 +1391,8 @@ void TextDocument::merge_span_collections()
merged_span.span.attributes.color = span_and_collection_index.collection_index > last_span_and_collection_index.collection_index ? span.attributes.color : last_span.attributes.color;
merged_span.span.attributes.bold = span.attributes.bold | last_span.attributes.bold;
merged_span.span.attributes.background_color = span.attributes.background_color.has_value() ? span.attributes.background_color.value() : last_span.attributes.background_color;
merged_span.span.attributes.underline = span.attributes.underline | last_span.attributes.underline;
merged_span.span.attributes.underline_color = span.attributes.underline_color.has_value() ? span.attributes.underline_color.value() : last_span.attributes.underline_color;
merged_span.span.attributes.underline_style = span.attributes.underline_style;
merged_span.span.attributes.underline_style = span.attributes.underline_style.has_value() ? span.attributes.underline_style : last_span.attributes.underline_style;
merged_spans.append(move(merged_span));
if (span.range.end() == last_span.range.end())

View file

@ -503,7 +503,7 @@ void TextEditor::paint_event(PaintEvent& event)
} else {
painter.draw_text(rect, raw_text, font, alignment, attributes.color);
}
if (attributes.underline) {
if (attributes.underline_style.has_value()) {
auto bottom_left = [&]() {
auto point = rect.bottom_left().translated(0, 1);
@ -2493,7 +2493,7 @@ void TextEditor::on_search_results(GUI::TextRange current, Vector<GUI::TextRange
span.attributes.color = Color::from_argb(0xff000000); // So text without spans from a highlighter will have color
if (i == m_search_result_index) {
span.attributes.bold = true;
span.attributes.underline = true;
span.attributes.underline_style = Gfx::TextAttributes::UnderlineStyle::Solid;
}
spans.append(move(span));
}

View file

@ -20,11 +20,10 @@ struct TextAttributes {
Color color;
Optional<Color> background_color {};
bool underline { false };
bool bold { false };
Optional<UnderlineStyle> underline_style {};
Optional<Color> underline_color {};
UnderlineStyle underline_style { UnderlineStyle::Solid };
};
}

View file

@ -131,7 +131,7 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
case Parser::Token::Type::BadUrl:
case Parser::Token::Type::BadString:
// FIXME: Error highlighting color in palette?
highlight(token.start_position().line, token.start_position().column, token.end_position().line, token.end_position().column, { Color(Color::NamedColor::Red), {}, false, true }, token.type());
highlight(token.start_position().line, token.start_position().column, token.end_position().line, token.end_position().column, { Color(Color::NamedColor::Red), {}, true }, token.type());
break;
case Parser::Token::Type::EndOfFile:

View file

@ -153,7 +153,7 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
token->start_position().column + token_start_offset,
token->start_position().line,
token->start_position().column + token_start_offset + token->tag_name().length(),
{ palette.syntax_keyword(), {}, false, true },
{ palette.syntax_keyword(), {}, true },
token->is_start_tag() ? AugmentedTokenKind::OpenTag : AugmentedTokenKind::CloseTag);
token->for_each_attribute([&](auto& attribute) {