diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-20 23:11:00 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-20 23:11:00 +0100 |
commit | ed2303e2d8f795a7c1bd597fed9f77afe526c228 (patch) | |
tree | a1af76d95488c9359a9086953f434be8dc59de3a /LibGUI | |
parent | be4533717afe45196eb172330046aa0499d02c7c (diff) | |
download | serenity-ed2303e2d8f795a7c1bd597fed9f77afe526c228.zip |
TextEditor: The delete key should work even when there's no selection.
Diffstat (limited to 'LibGUI')
-rw-r--r-- | LibGUI/GTextEditor.cpp | 49 | ||||
-rw-r--r-- | LibGUI/GTextEditor.h | 3 |
2 files changed, 29 insertions, 23 deletions
diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp index 06ab76f1a2..e6bb060318 100644 --- a/LibGUI/GTextEditor.cpp +++ b/LibGUI/GTextEditor.cpp @@ -382,28 +382,7 @@ void GTextEditor::keydown_event(GKeyEvent& event) } if (event.key() == KeyCode::Key_Delete) { - if (has_selection()) { - delete_selection(); - return; - } - if (m_cursor.column() < current_line().length()) { - // Delete within line - current_line().remove(m_cursor.column()); - update_content_size(); - update_cursor(); - return; - } - if (m_cursor.column() == current_line().length() && m_cursor.line() != line_count() - 1) { - // Delete at end of line; merge with next line - auto& next_line = *m_lines[m_cursor.line() + 1]; - int previous_length = current_line().length(); - current_line().append(next_line.characters(), next_line.length()); - m_lines.remove(m_cursor.line() + 1); - update_content_size(); - update(); - set_cursor(m_cursor.line(), previous_length); - return; - } + do_delete(); return; } @@ -413,6 +392,32 @@ void GTextEditor::keydown_event(GKeyEvent& event) return GWidget::keydown_event(event); } +void GTextEditor::do_delete() +{ + if (has_selection()) { + delete_selection(); + return; + } + if (m_cursor.column() < current_line().length()) { + // Delete within line + current_line().remove(m_cursor.column()); + update_content_size(); + update_cursor(); + return; + } + if (m_cursor.column() == current_line().length() && m_cursor.line() != line_count() - 1) { + // Delete at end of line; merge with next line + auto& next_line = *m_lines[m_cursor.line() + 1]; + int previous_length = current_line().length(); + current_line().append(next_line.characters(), next_line.length()); + m_lines.remove(m_cursor.line() + 1); + update_content_size(); + update(); + set_cursor(m_cursor.line(), previous_length); + return; + } +} + void GTextEditor::insert_at_cursor(const String& text) { // FIXME: This should obviously not be implemented this way. diff --git a/LibGUI/GTextEditor.h b/LibGUI/GTextEditor.h index ad662133ad..9e5b88cf74 100644 --- a/LibGUI/GTextEditor.h +++ b/LibGUI/GTextEditor.h @@ -93,7 +93,7 @@ public: void cut(); void copy(); void paste(); - void delete_selection(); + void do_delete(); Function<void(GTextEditor&)> on_return_pressed; Function<void(GTextEditor&)> on_escape_pressed; @@ -150,6 +150,7 @@ private: Rect ruler_content_rect(int line) const; void toggle_selection_if_needed_for_event(const GKeyEvent&); void insert_at_cursor_or_replace_selection(const String&); + void delete_selection(); Type m_type { MultiLine }; |