mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:57:35 +00:00
LibGUI: Indent selected text on tab press
If selected text is less than a whole line, usual delete/replace takes place. Otherwise, if the selected text is a whole line or spans multiple lines, the selection will be indented.
This commit is contained in:
parent
80705a72bd
commit
2fbaa7996c
4 changed files with 80 additions and 2 deletions
|
@ -932,6 +932,33 @@ String ReplaceAllTextCommand::action_text() const
|
|||
return m_action_text;
|
||||
}
|
||||
|
||||
IndentSelection::IndentSelection(TextDocument& document, size_t tab_width, TextRange const& range)
|
||||
: TextDocumentUndoCommand(document)
|
||||
, m_tab_width(tab_width)
|
||||
, m_range(range)
|
||||
{
|
||||
}
|
||||
|
||||
void IndentSelection::redo()
|
||||
{
|
||||
auto const tab = String::repeated(' ', m_tab_width);
|
||||
|
||||
for (size_t i = m_range.start().line(); i <= m_range.end().line(); i++) {
|
||||
m_document.insert_at({ i, 0 }, tab, m_client);
|
||||
}
|
||||
|
||||
m_document.set_all_cursors(m_range.start());
|
||||
}
|
||||
|
||||
void IndentSelection::undo()
|
||||
{
|
||||
for (size_t i = m_range.start().line(); i <= m_range.end().line(); i++) {
|
||||
m_document.remove({ { i, 0 }, { i, m_tab_width } });
|
||||
}
|
||||
|
||||
m_document.set_all_cursors(m_range.start());
|
||||
}
|
||||
|
||||
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