diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-02-23 15:25:29 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-02-28 13:23:55 +0100 |
commit | 3d25b4eb3409107256cd2abb22ecd0968dfe5228 (patch) | |
tree | eaf9556537beadad2466ed8de906e0d2861e2b78 /Userland/Libraries/LibGUI/TextDocument.h | |
parent | 96cf9355b2ebddfd01ee1c55e2f452325ca4d429 (diff) | |
download | serenity-3d25b4eb3409107256cd2abb22ecd0968dfe5228.zip |
LibGUI: Add folding regions to TextDocument
A `TextDocumentFoldingRegion` represents a region of the document which
the user can collapse/expand to make code easier to navigate.
Diffstat (limited to 'Userland/Libraries/LibGUI/TextDocument.h')
-rw-r--r-- | Userland/Libraries/LibGUI/TextDocument.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TextDocument.h b/Userland/Libraries/LibGUI/TextDocument.h index 48c1452055..a79073b7d9 100644 --- a/Userland/Libraries/LibGUI/TextDocument.h +++ b/Userland/Libraries/LibGUI/TextDocument.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2018-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 */ @@ -35,6 +36,13 @@ struct TextDocumentSpan { bool is_skippable { false }; }; +struct TextDocumentFoldingRegion { + TextRange range; + bool is_folded { false }; + // This pointer is only used to identify that two TDFRs are the same. + RawPtr<class TextDocumentLine> line_ptr; +}; + class TextDocument : public RefCounted<TextDocument> { public: enum class SearchShouldWrap { @@ -79,6 +87,16 @@ public: TextDocumentSpan const* span_at(TextPosition const&) const; + void set_folding_regions(Vector<TextDocumentFoldingRegion>); + bool has_folding_regions() const { return !m_folding_regions.is_empty(); } + Vector<TextDocumentFoldingRegion>& folding_regions() { return m_folding_regions; } + Vector<TextDocumentFoldingRegion> const& folding_regions() const { return m_folding_regions; } + Optional<TextDocumentFoldingRegion&> folding_region_starting_on_line(size_t line); + // Returns all folded FoldingRegions that are not contained inside another folded region. + Vector<TextDocumentFoldingRegion const&> currently_folded_regions() const; + // Returns true if any part of the line is currently visible. (Not inside a folded FoldingRegion.) + bool line_is_visible(size_t line) const; + void append_line(NonnullOwnPtr<TextDocumentLine>); NonnullOwnPtr<TextDocumentLine> take_line(size_t line_index); void remove_line(size_t line_index); @@ -148,6 +166,7 @@ private: NonnullOwnPtrVector<TextDocumentLine> m_lines; HashMap<u32, Vector<TextDocumentSpan>> m_span_collections; Vector<TextDocumentSpan> m_spans; + Vector<TextDocumentFoldingRegion> m_folding_regions; HashTable<Client*> m_clients; bool m_client_notifications_enabled { true }; |