mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 04:39:06 +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
Notes:
sideshowbarker
2024-07-17 22:41:14 +09:00
Author: https://github.com/huttongrabiel
Commit: 2fbaa7996c
Pull-request: https://github.com/SerenityOS/serenity/pull/13269
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/linusg
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