1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 21:35:06 +00:00

LibGUI: Add underlines to highlighting

This commit is contained in:
Oriko 2020-03-12 16:36:25 +02:00 committed by Andreas Kling
parent b58893cfe1
commit 6d89f48dd8
6 changed files with 25 additions and 2 deletions

View file

@ -425,6 +425,7 @@ void TextEditor::paint_event(PaintEvent& event)
const Gfx::Font* font = &this->font();
Color color;
Optional<Color> background_color;
bool underline = false;
TextPosition physical_position(line_index, start_of_visual_line + i);
// FIXME: This is *horribly* inefficient.
for (auto& span : document().spans()) {
@ -434,11 +435,15 @@ void TextEditor::paint_event(PaintEvent& event)
if (span.font)
font = span.font;
background_color = span.background_color;
underline = span.is_underlined;
break;
}
if (background_color.has_value())
painter.fill_rect(character_rect, background_color.value());
painter.draw_text(character_rect, visual_line_text.substring_view(i, 1), *font, m_text_alignment, color);
if (underline) {
painter.draw_line(character_rect.bottom_left().translated(0, 1), character_rect.bottom_right().translated(0, 1), color);
}
character_rect.move_by(advance, 0);
}
}
@ -1490,6 +1495,14 @@ void TextEditor::flush_pending_change_notification_if_needed()
m_has_pending_change_notification = false;
}
const SyntaxHighlighter* TextEditor::syntax_highlighter() const
{
if (m_highlighter)
return m_highlighter.ptr();
else
return nullptr;
}
void TextEditor::set_syntax_highlighter(OwnPtr<SyntaxHighlighter> highlighter)
{
if (m_highlighter)