2023-08-29 06:13:41 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2023, Ali Mohammad Pur <mpfard@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2026-01-22 09:05:06 -03:00
|
|
|
#include <AK/RefCounted.h>
|
2026-06-06 10:38:27 -03:00
|
|
|
#include <AK/String.h>
|
2026-06-05 07:39:55 -03:00
|
|
|
#include <AK/Vector.h>
|
2023-08-29 06:13:41 -03:00
|
|
|
#include <LibGfx/TextAttributes.h>
|
|
|
|
|
#include <LibSyntax/Forward.h>
|
|
|
|
|
#include <LibSyntax/TextRange.h>
|
|
|
|
|
|
|
|
|
|
namespace Syntax {
|
|
|
|
|
|
|
|
|
|
struct TextDocumentSpan {
|
|
|
|
|
TextRange range;
|
|
|
|
|
Gfx::TextAttributes attributes;
|
|
|
|
|
u64 data { 0 };
|
|
|
|
|
bool is_skippable { false };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TextDocumentLine {
|
|
|
|
|
public:
|
|
|
|
|
explicit TextDocumentLine(Document&);
|
|
|
|
|
explicit TextDocumentLine(Document&, StringView);
|
|
|
|
|
|
2026-06-06 10:38:27 -03:00
|
|
|
Utf8View view() const LIFETIME_BOUND { return m_text.code_points(); }
|
|
|
|
|
size_t length() const { return m_length; }
|
2023-08-29 06:13:41 -03:00
|
|
|
bool set_text(Document&, StringView);
|
|
|
|
|
void clear(Document&);
|
|
|
|
|
|
|
|
|
|
private:
|
2026-06-06 10:38:27 -03:00
|
|
|
String m_text;
|
|
|
|
|
size_t m_length { 0 };
|
2023-08-29 06:13:41 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Document : public RefCounted<Document> {
|
|
|
|
|
public:
|
|
|
|
|
Document() = default;
|
|
|
|
|
virtual ~Document() = default;
|
|
|
|
|
|
2026-06-05 07:39:55 -03:00
|
|
|
void set_spans(Vector<TextDocumentSpan> spans);
|
2023-08-29 06:13:41 -03:00
|
|
|
Vector<TextDocumentSpan>& spans() { return m_spans; }
|
|
|
|
|
|
|
|
|
|
virtual TextDocumentLine const& line(size_t line_index) const = 0;
|
|
|
|
|
virtual TextDocumentLine& line(size_t line_index) = 0;
|
|
|
|
|
|
|
|
|
|
virtual void update_views(Badge<TextDocumentLine>) = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
Vector<TextDocumentSpan> m_spans;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|