From 8fa466e4965e1e91deb3eef1c20645079056445d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 27 Oct 2019 10:42:48 +0100 Subject: [PATCH] GTextEditor: Backspace over soft tabs This makes the backspace erase backwards until the next soft tab stop. We currently always use 4 as the soft tab width, but I suppose we could make it configurable at some point. :^) --- Libraries/LibGUI/GTextEditor.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Libraries/LibGUI/GTextEditor.cpp b/Libraries/LibGUI/GTextEditor.cpp index a82435e635..3af90498d5 100644 --- a/Libraries/LibGUI/GTextEditor.cpp +++ b/Libraries/LibGUI/GTextEditor.cpp @@ -622,10 +622,22 @@ void GTextEditor::keydown_event(GKeyEvent& event) return; } if (m_cursor.column() > 0) { + int erase_count = 1; + if (current_line().first_non_whitespace_column() >= m_cursor.column()) { + int new_column; + if (m_cursor.column() % m_soft_tab_width == 0) + new_column = m_cursor.column() - m_soft_tab_width; + else + new_column = (m_cursor.column() / m_soft_tab_width) * m_soft_tab_width; + erase_count = m_cursor.column() - new_column; + } + // Backspace within line - current_line().remove(m_cursor.column() - 1); + for (int i = 0; i < erase_count; ++i) { + current_line().remove(m_cursor.column() - 1 - i); + } update_content_size(); - set_cursor(m_cursor.line(), m_cursor.column() - 1); + set_cursor(m_cursor.line(), m_cursor.column() - erase_count); did_change(); return; }