mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 06:57:35 +00:00
LibGUI: Consolidate and simplify commands used for insertion/removal
This patch adds InsertTextCommand and RemoveTextCommand. These two commands are used to ... insert and remove text :^) The bulk of the logic is moved into GTextDocument, and we now use the command's redo() virtual to perform the action. Or in other words, when you type into the text editor, we create an InsertTextCommand, push it onto the undo stack, and call redo() on it immediately. That's how the text gets inserted. This makes it quite easy to implement more commands, as there is no distinction between a redo() and the initial application.
This commit is contained in:
parent
f430da1d45
commit
00a91bb02c
4 changed files with 179 additions and 288 deletions
|
@ -33,49 +33,26 @@ protected:
|
|||
GTextDocument& m_document;
|
||||
};
|
||||
|
||||
class InsertCharacterCommand : public GTextDocumentUndoCommand {
|
||||
class InsertTextCommand : public GTextDocumentUndoCommand {
|
||||
public:
|
||||
InsertCharacterCommand(GTextDocument&, char, GTextPosition);
|
||||
InsertTextCommand(GTextDocument&, const String&, const GTextPosition&);
|
||||
virtual void undo() override;
|
||||
virtual void redo() override;
|
||||
|
||||
private:
|
||||
char m_character;
|
||||
GTextPosition m_text_position;
|
||||
String m_text;
|
||||
GTextRange m_range;
|
||||
};
|
||||
|
||||
class RemoveCharacterCommand : public GTextDocumentUndoCommand {
|
||||
class RemoveTextCommand : public GTextDocumentUndoCommand {
|
||||
public:
|
||||
RemoveCharacterCommand(GTextDocument&, char, GTextPosition);
|
||||
RemoveTextCommand(GTextDocument&, const String&, const GTextRange&);
|
||||
virtual void undo() override;
|
||||
virtual void redo() override;
|
||||
|
||||
private:
|
||||
char m_character;
|
||||
GTextPosition m_text_position;
|
||||
};
|
||||
|
||||
class RemoveLineCommand : public GTextDocumentUndoCommand {
|
||||
public:
|
||||
RemoveLineCommand(GTextDocument&, String, GTextPosition, bool has_merged_content);
|
||||
virtual void undo() override;
|
||||
virtual void redo() override;
|
||||
|
||||
private:
|
||||
String m_line_content;
|
||||
GTextPosition m_text_position;
|
||||
bool m_has_merged_content;
|
||||
};
|
||||
|
||||
class CreateLineCommand : public GTextDocumentUndoCommand {
|
||||
public:
|
||||
CreateLineCommand(GTextDocument&, Vector<char> line_content, GTextPosition);
|
||||
virtual void undo() override;
|
||||
virtual void redo() override;
|
||||
|
||||
private:
|
||||
Vector<char> m_line_content;
|
||||
GTextPosition m_text_position;
|
||||
String m_text;
|
||||
GTextRange m_range;
|
||||
};
|
||||
|
||||
class GTextDocument : public RefCounted<GTextDocument> {
|
||||
|
@ -152,6 +129,10 @@ public:
|
|||
void notify_did_change();
|
||||
void set_all_cursors(const GTextPosition&);
|
||||
|
||||
GTextPosition insert_at(const GTextPosition&, char);
|
||||
GTextPosition insert_at(const GTextPosition&, const StringView&);
|
||||
void remove(const GTextRange&);
|
||||
|
||||
private:
|
||||
explicit GTextDocument(Client* client);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue