1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 10:18:15 +09:00

LibGUI: Unindent selected text on shift+tab press

Selected text is unindented when Shift+Tab is pressed. Select text,
indent it with Tab, then unindent with Shift+Tab.
This commit is contained in:
huttongrabiel 2022-06-18 12:03:49 -07:00 committed by Sam Atkins
parent 2fbaa7996c
commit 9369610bf4
Notes: sideshowbarker 2024-07-17 09:36:21 +09:00
4 changed files with 63 additions and 0 deletions

View file

@ -869,6 +869,10 @@ void TextEditor::keydown_event(KeyEvent& event)
if (event.key() == KeyCode::Key_Tab) {
if (has_selection()) {
if (event.modifiers() == Mod_Shift) {
unindent_selection();
return;
}
if (is_indenting_selection()) {
indent_selection();
return;
@ -988,6 +992,23 @@ void TextEditor::indent_selection()
}
}
void TextEditor::unindent_selection()
{
auto const selection_start = m_selection.start() > m_selection.end() ? m_selection.end() : m_selection.start();
auto const selection_end = m_selection.end() > m_selection.start() ? m_selection.end() : m_selection.start();
if (current_line().first_non_whitespace_column() != 0) {
if (current_line().first_non_whitespace_column() > m_soft_tab_width && selection_start.column() != 0) {
m_selection.set_start({ selection_start.line(), selection_start.column() - m_soft_tab_width });
m_selection.set_end({ selection_end.line(), selection_end.column() - m_soft_tab_width });
} else if (selection_start.column() != 0) {
m_selection.set_start({ selection_start.line(), selection_start.column() - current_line().leading_spaces() });
m_selection.set_end({ selection_end.line(), selection_end.column() - current_line().leading_spaces() });
}
execute<UnindentSelection>(m_soft_tab_width, TextRange(selection_start, selection_end));
}
}
void TextEditor::delete_previous_word()
{
TextRange to_erase(document().first_word_before(m_cursor, true), m_cursor);