mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +00:00
LibGUI: Shift+Tab unindents line
Previously, pressing Shift+Tab would indent the line if no selection was given. While with a selection, it would be unindented. With this change, pressing Shift+Tab with no selection unindents the current line. For this, add unindent_line() helper function. This function unindents the current line by at most one tab width if it starts with whitespace, regardless of cursor position.
This commit is contained in:
committed by
Andreas Kling
parent
03d0c7a5b6
commit
0ea399d8d6
@@ -918,6 +918,11 @@ void TextEditor::keydown_event(KeyEvent& event)
|
||||
indent_selection();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (event.modifiers() == Mod_Shift) {
|
||||
unindent_line();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1050,6 +1055,18 @@ void TextEditor::unindent_selection()
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditor::unindent_line()
|
||||
{
|
||||
if (current_line().first_non_whitespace_column() != 0) {
|
||||
auto const unindent_size = current_line().leading_spaces() < m_soft_tab_width ? current_line().leading_spaces() : m_soft_tab_width;
|
||||
auto const temp_column = m_cursor.column();
|
||||
|
||||
execute<UnindentSelection>(unindent_size, TextRange({ m_cursor.line(), 0 }, { m_cursor.line(), line(m_cursor.line()).length() }));
|
||||
|
||||
set_cursor({ m_cursor.line(), temp_column <= unindent_size ? 0 : temp_column - unindent_size });
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditor::delete_previous_word()
|
||||
{
|
||||
TextRange to_erase(document().first_word_before(m_cursor, true), m_cursor);
|
||||
|
||||
Reference in New Issue
Block a user