1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 10:55:07 +00:00

LibGUI: Give GTextDocument access to the GTextEditor during commands

It's useful for the GTextDocument to have access to the initiating
GTextEditor widget during the initial execution of a command.

Since commands are executed via calls to GUndoCommand::redo(), we do
this by wrapping the invocation of redo() in a new helper called
GTextDocumentUndoCommand::execute_from(GTextDocument::Client).

This is then used to fetch the current auto-indentation feature state
and the soft tab width, both used by text insertion.
This commit is contained in:
Andreas Kling 2020-01-23 21:04:59 +01:00
parent 03d73cbaae
commit 14b83ee12f
3 changed files with 57 additions and 43 deletions

View file

@ -60,9 +60,11 @@ public:
bool is_readonly() const { return m_readonly; }
void set_readonly(bool);
bool is_automatic_indentation_enabled() const { return m_automatic_indentation_enabled; }
virtual bool is_automatic_indentation_enabled() const final { return m_automatic_indentation_enabled; }
void set_automatic_indentation_enabled(bool enabled) { m_automatic_indentation_enabled = enabled; }
virtual int soft_tab_width() const final { return m_soft_tab_width; }
bool is_line_wrapping_enabled() const { return m_line_wrapping_enabled; }
void set_line_wrapping_enabled(bool);
@ -202,7 +204,7 @@ private:
inline void execute(Args&&... args)
{
auto command = make<T>(*m_document, forward<Args>(args)...);
command->redo();
command->execute_from(*this);
m_document->add_to_undo_stack(move(command));
}