mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 14:55:06 +00:00
LibGUI: Support multiple GTextEditors editing the same GTextDocument
With this patch, you can now assign the same GTextDocument to multiple GTextEditor widgets via GTextEditor::set_document(). The editors have independent cursors and selection, but all changes are shared, and immediately propagate to all editors. This is very unoptimized and will do lots of unnecessary invalidation, especially line re-wrapping and repainting over and over again.
This commit is contained in:
parent
f96c683543
commit
9b13a3905b
4 changed files with 101 additions and 58 deletions
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/HashTable.h>
|
||||
#include <AK/NonnullOwnPtrVector.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
|
@ -26,6 +27,7 @@ public:
|
|||
virtual void document_did_insert_line(int) = 0;
|
||||
virtual void document_did_remove_line(int) = 0;
|
||||
virtual void document_did_remove_all_lines() = 0;
|
||||
virtual void document_did_change() = 0;
|
||||
};
|
||||
|
||||
static NonnullRefPtr<GTextDocument> create(Client* client = nullptr)
|
||||
|
@ -55,6 +57,8 @@ public:
|
|||
void register_client(Client&);
|
||||
void unregister_client(Client&);
|
||||
|
||||
void update_views(Badge<GTextDocumentLine>);
|
||||
|
||||
private:
|
||||
explicit GTextDocument(Client* client);
|
||||
|
||||
|
@ -69,20 +73,20 @@ class GTextDocumentLine {
|
|||
friend class GTextDocument;
|
||||
|
||||
public:
|
||||
explicit GTextDocumentLine();
|
||||
explicit GTextDocumentLine(const StringView&);
|
||||
explicit GTextDocumentLine(GTextDocument&);
|
||||
explicit GTextDocumentLine(GTextDocument&, const StringView&);
|
||||
|
||||
StringView view() const { return { characters(), length() }; }
|
||||
const char* characters() const { return m_text.data(); }
|
||||
int length() const { return m_text.size() - 1; }
|
||||
void set_text(const StringView&);
|
||||
void append(char);
|
||||
void prepend(char);
|
||||
void insert(int index, char);
|
||||
void remove(int index);
|
||||
void append(const char*, int);
|
||||
void truncate(int length);
|
||||
void clear();
|
||||
void set_text(GTextDocument&, const StringView&);
|
||||
void append(GTextDocument&, char);
|
||||
void prepend(GTextDocument&, char);
|
||||
void insert(GTextDocument&, int index, char);
|
||||
void remove(GTextDocument&, int index);
|
||||
void append(GTextDocument&, const char*, int);
|
||||
void truncate(GTextDocument&, int length);
|
||||
void clear(GTextDocument&);
|
||||
int first_non_whitespace_column() const;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue