Explorar o código

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. :^)
Andreas Kling %!s(int64=5) %!d(string=hai) anos
pai
achega
8fa466e496
Modificáronse 1 ficheiros con 14 adicións e 2 borrados
  1. 14 2
      Libraries/LibGUI/GTextEditor.cpp

+ 14 - 2
Libraries/LibGUI/GTextEditor.cpp

@@ -622,10 +622,22 @@ void GTextEditor::keydown_event(GKeyEvent& event)
             return;
             return;
         }
         }
         if (m_cursor.column() > 0) {
         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
             // 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();
             update_content_size();
-            set_cursor(m_cursor.line(), m_cursor.column() - 1);
+            set_cursor(m_cursor.line(), m_cursor.column() - erase_count);
             did_change();
             did_change();
             return;
             return;
         }
         }