1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-07 20:17:34 +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:
Andreas Kling 2019-11-30 16:50:24 +01:00
parent f430da1d45
commit 00a91bb02c
4 changed files with 179 additions and 288 deletions

View file

@ -152,8 +152,6 @@ private:
const GTextDocumentLine& line(int index) const { return document().line(index); }
GTextDocumentLine& current_line() { return line(m_cursor.line()); }
const GTextDocumentLine& current_line() const { return line(m_cursor.line()); }
void insert_at_cursor(char);
void insert_at_cursor(const StringView&);
int ruler_width() const;
Rect ruler_content_rect(int line) const;
void toggle_selection_if_needed_for_event(const GKeyEvent&);
@ -174,6 +172,14 @@ private:
int visual_line_containing(int line_index, int column) const;
void recompute_visual_lines(int line_index);
template<class T, class... Args>
inline void execute(Args&&... args)
{
auto command = make<T>(*m_document, forward<Args>(args)...);
command->redo();
m_document->add_to_undo_stack(move(command));
}
Type m_type { MultiLine };
GTextPosition m_cursor;