From ee81c1b07a9cadc76b0b8a82ff81cbe6a0036466 Mon Sep 17 00:00:00 2001 From: ForLoveOfCats Date: Sun, 24 Apr 2022 21:04:21 -0400 Subject: [PATCH] LibGUI: Split InsertTextCommand undo/redo based on whitespace --- Userland/Libraries/LibGUI/TextDocument.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp index 2d8e15cd40..40a504a162 100644 --- a/Userland/Libraries/LibGUI/TextDocument.cpp +++ b/Userland/Libraries/LibGUI/TextDocument.cpp @@ -764,16 +764,22 @@ bool InsertTextCommand::merge_with(GUI::Command const& other) { if (!is(other)) return false; - auto& typed_other = static_cast(other); + + auto const& typed_other = static_cast(other); + if (typed_other.m_text.is_whitespace() && !m_text.is_whitespace()) + return false; // Skip if other is whitespace while this is not + if (m_range.end() != typed_other.m_range.start()) return false; if (m_range.start().line() != m_range.end().line()) 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; }