mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:37:35 +00:00
LibWeb: Add some folding regions to HTML syntax highlighter
This adds the regions generated from embedded CSS and JS, and also for HTML block comments. The glaring omission is that we don't add them for start/end tags. HTML allows start and end tags to not always match up, and I believe that's going to require some variation on the adoption-agency algorithm to make it work correctly.
This commit is contained in:
parent
e239e1ccbc
commit
c7736ef410
1 changed files with 10 additions and 0 deletions
|
@ -41,6 +41,8 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
|
|||
auto text = m_client->get_text();
|
||||
clear_nested_token_pairs();
|
||||
|
||||
// FIXME: Add folding regions for start and end tags.
|
||||
Vector<GUI::TextDocumentFoldingRegion> folding_regions;
|
||||
Vector<GUI::TextDocumentSpan> spans;
|
||||
auto highlight = [&](auto start_line, auto start_column, auto end_line, auto end_column, Gfx::TextAttributes attributes, AugmentedTokenKind kind) {
|
||||
if (start_line > end_line || (start_line == end_line && start_column >= end_column)) {
|
||||
|
@ -101,6 +103,7 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
|
|||
}
|
||||
|
||||
spans.extend(proxy_client.corrected_spans());
|
||||
folding_regions.extend(proxy_client.corrected_folding_regions());
|
||||
substring_builder.clear();
|
||||
} else if (state == State::CSS) {
|
||||
Syntax::ProxyHighlighterClient proxy_client {
|
||||
|
@ -118,6 +121,7 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
|
|||
}
|
||||
|
||||
spans.extend(proxy_client.corrected_spans());
|
||||
folding_regions.extend(proxy_client.corrected_folding_regions());
|
||||
substring_builder.clear();
|
||||
}
|
||||
state = State::HTML;
|
||||
|
@ -138,6 +142,11 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
|
|||
token->end_position().column,
|
||||
{ palette.syntax_comment(), {} },
|
||||
AugmentedTokenKind::Comment);
|
||||
|
||||
GUI::TextDocumentFoldingRegion region;
|
||||
region.range.set_start({ token->start_position().line, token->start_position().column + comment_prefix()->length() });
|
||||
region.range.set_end({ token->end_position().line, token->end_position().column - comment_suffix()->length() });
|
||||
folding_regions.append(move(region));
|
||||
} else if (token->is_start_tag() || token->is_end_tag()) {
|
||||
highlight(
|
||||
token->start_position().line,
|
||||
|
@ -183,6 +192,7 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
|
|||
}
|
||||
|
||||
m_client->do_set_spans(move(spans));
|
||||
m_client->do_set_folding_regions(move(folding_regions));
|
||||
m_has_brace_buddies = false;
|
||||
highlight_matching_token_pair();
|
||||
m_client->do_update();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue