1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +00:00

LibGUI: Implement merging of TextDocument's InsertTextCommand

When performing multiple text insertions in a row, they will now
be merged into a single InsertTextCommand.
This commit is contained in:
Andreas Kling 2021-05-08 16:52:08 +02:00
parent ff912946ae
commit ff6bac4854
2 changed files with 16 additions and 0 deletions

View file

@ -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();