mirror of
https://github.com/RGBCube/serenity
synced 2025-07-02 23:12:08 +00:00
LibGUI: Assign folding regions for GML files
Each {} block is now treated as a folding region, so that they can be collapsed and expanded in TextEditor, GML Playground, HackStudio, and anywhere else that uses the syntax highlighter. :^)
This commit is contained in:
parent
d169af117d
commit
cac14a3f0a
1 changed files with 19 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -44,7 +45,11 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
|
|||
Lexer lexer(text);
|
||||
auto tokens = lexer.lex();
|
||||
|
||||
Vector<Token> folding_region_start_tokens;
|
||||
|
||||
Vector<GUI::TextDocumentSpan> spans;
|
||||
Vector<GUI::TextDocumentFoldingRegion> folding_regions;
|
||||
|
||||
for (auto& token : tokens) {
|
||||
GUI::TextDocumentSpan span;
|
||||
span.range.set_start({ token.m_start.line, token.m_start.column });
|
||||
|
@ -55,8 +60,22 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
|
|||
span.is_skippable = false;
|
||||
span.data = static_cast<u64>(token.m_type);
|
||||
spans.append(span);
|
||||
|
||||
// Create folding regions for {} blocks
|
||||
if (token.m_type == Token::Type::LeftCurly) {
|
||||
folding_region_start_tokens.append(token);
|
||||
} else if (token.m_type == Token::Type::RightCurly) {
|
||||
if (!folding_region_start_tokens.is_empty()) {
|
||||
auto left_curly = folding_region_start_tokens.take_last();
|
||||
GUI::TextDocumentFoldingRegion region;
|
||||
region.range.set_start({ left_curly.m_end.line, left_curly.m_end.column });
|
||||
region.range.set_end({ token.m_start.line, token.m_start.column });
|
||||
folding_regions.append(region);
|
||||
}
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue