summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2023-03-03 14:40:58 +0000
committerAndreas Kling <kling@serenityos.org>2023-03-03 21:56:42 +0100
commitc7736ef41017288b2bb8d41cf51f2b1366ed5a35 (patch)
treed9fffc882fb7c005bbb4c8c2ba6a56e06de8a820 /Userland
parente239e1ccbc81d43e891261ce85b4d0720ec984d4 (diff)
downloadserenity-c7736ef41017288b2bb8d41cf51f2b1366ed5a35.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.cpp b/Userland/Libraries/LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.cpp
index feb247cde8..7b94272def 100644
--- a/Userland/Libraries/LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.cpp
+++ b/Userland/Libraries/LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.cpp
@@ -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();