summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibGUI/TextDocument.cpp15
-rw-r--r--Userland/Libraries/LibGUI/TextDocument.h1
2 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp
index 0beef4170b..78a23a30b0 100644
--- a/Userland/Libraries/LibGUI/TextDocument.cpp
+++ b/Userland/Libraries/LibGUI/TextDocument.cpp
@@ -719,6 +719,21 @@ InsertTextCommand::InsertTextCommand(TextDocument& document, const String& text,
{
}
+bool InsertTextCommand::merge_with(GUI::Command const& other)
+{
+ if (!is<InsertTextCommand>(other))
+ return false;
+ auto& typed_other = static_cast<InsertTextCommand const&>(other);
+ if (m_range.end() != typed_other.m_range.start())
+ return false;
+ StringBuilder builder(m_text.length() + typed_other.m_text.length());
+ builder.append(m_text);
+ builder.append(typed_other.m_text);
+ m_text = builder.to_string();
+ m_range.set_end(typed_other.m_range.end());
+ return true;
+}
+
void InsertTextCommand::perform_formatting(const TextDocument::Client& client)
{
const size_t tab_width = client.soft_tab_width();
diff --git a/Userland/Libraries/LibGUI/TextDocument.h b/Userland/Libraries/LibGUI/TextDocument.h
index aac61254fb..f3a4c9a0cf 100644
--- a/Userland/Libraries/LibGUI/TextDocument.h
+++ b/Userland/Libraries/LibGUI/TextDocument.h
@@ -206,6 +206,7 @@ public:
virtual void perform_formatting(const TextDocument::Client&) override;
virtual void undo() override;
virtual void redo() override;
+ virtual bool merge_with(GUI::Command const&) override;
const String& text() const { return m_text; }
const TextRange& range() const { return m_range; }