mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +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:
parent
ff912946ae
commit
ff6bac4854
2 changed files with 16 additions and 0 deletions
|
@ -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)
|
void InsertTextCommand::perform_formatting(const TextDocument::Client& client)
|
||||||
{
|
{
|
||||||
const size_t tab_width = client.soft_tab_width();
|
const size_t tab_width = client.soft_tab_width();
|
||||||
|
|
|
@ -206,6 +206,7 @@ public:
|
||||||
virtual void perform_formatting(const TextDocument::Client&) override;
|
virtual void perform_formatting(const TextDocument::Client&) override;
|
||||||
virtual void undo() override;
|
virtual void undo() override;
|
||||||
virtual void redo() override;
|
virtual void redo() override;
|
||||||
|
virtual bool merge_with(GUI::Command const&) override;
|
||||||
const String& text() const { return m_text; }
|
const String& text() const { return m_text; }
|
||||||
const TextRange& range() const { return m_range; }
|
const TextRange& range() const { return m_range; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue