mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:08:12 +00:00
LibGUI+GMLPlayground: Replace text using ReplaceAllTextCommand
This commit is contained in:
parent
343d699627
commit
661e7d691e
5 changed files with 65 additions and 1 deletions
|
@ -884,6 +884,40 @@ void RemoveTextCommand::undo()
|
|||
m_document.set_all_cursors(new_cursor);
|
||||
}
|
||||
|
||||
ReplaceAllTextCommand::ReplaceAllTextCommand(GUI::TextDocument& document, String const& text, GUI::TextRange const& range)
|
||||
: TextDocumentUndoCommand(document)
|
||||
, m_text(text)
|
||||
, m_range(range)
|
||||
{
|
||||
}
|
||||
|
||||
void ReplaceAllTextCommand::redo()
|
||||
{
|
||||
m_document.remove(m_range);
|
||||
m_document.set_all_cursors(m_range.start());
|
||||
auto new_cursor = m_document.insert_at(m_range.start(), m_text, m_client);
|
||||
m_range.set_end(new_cursor);
|
||||
m_document.set_all_cursors(new_cursor);
|
||||
}
|
||||
|
||||
void ReplaceAllTextCommand::undo()
|
||||
{
|
||||
m_document.remove(m_range);
|
||||
m_document.set_all_cursors(m_range.start());
|
||||
auto new_cursor = m_document.insert_at(m_range.start(), m_text);
|
||||
m_document.set_all_cursors(new_cursor);
|
||||
}
|
||||
|
||||
bool ReplaceAllTextCommand::merge_with(GUI::Command const&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String ReplaceAllTextCommand::action_text() const
|
||||
{
|
||||
return "Playground format text";
|
||||
}
|
||||
|
||||
TextPosition TextDocument::insert_at(TextPosition const& position, StringView text, Client const* client)
|
||||
{
|
||||
TextPosition cursor = position;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue