From 3d25b4eb3409107256cd2abb22ecd0968dfe5228 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 23 Feb 2023 15:25:29 +0000 Subject: 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. --- Userland/Libraries/LibGUI/TextDocument.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Userland/Libraries/LibGUI/TextDocument.h') 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 * Copyright (c) 2022, the SerenityOS developers. + * Copyright (c) 2023, Sam Atkins * * 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 line_ptr; +}; + class TextDocument : public RefCounted { public: enum class SearchShouldWrap { @@ -79,6 +87,16 @@ public: TextDocumentSpan const* span_at(TextPosition const&) const; + void set_folding_regions(Vector); + bool has_folding_regions() const { return !m_folding_regions.is_empty(); } + Vector& folding_regions() { return m_folding_regions; } + Vector const& folding_regions() const { return m_folding_regions; } + Optional folding_region_starting_on_line(size_t line); + // Returns all folded FoldingRegions that are not contained inside another folded region. + Vector 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); NonnullOwnPtr take_line(size_t line_index); void remove_line(size_t line_index); @@ -148,6 +166,7 @@ private: NonnullOwnPtrVector m_lines; HashMap> m_span_collections; Vector m_spans; + Vector m_folding_regions; HashTable m_clients; bool m_client_notifications_enabled { true }; -- cgit v1.2.3