diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-25 13:13:46 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-25 13:14:02 +0100 |
commit | 838a06096ac2522f9f5b6a2fb8a8096290520db5 (patch) | |
tree | df9bc3e6e83d372209f61d7445df6b0c0f7016ac | |
parent | fceeb9b6958f42bc4227dab4f931a8f49ba67ad9 (diff) | |
download | serenity-838a06096ac2522f9f5b6a2fb8a8096290520db5.zip |
GTextEditor: Shift+Delete should delete the current line.
-rw-r--r-- | LibGUI/GTextEditor.cpp | 25 | ||||
-rw-r--r-- | LibGUI/GTextEditor.h | 1 |
2 files changed, 22 insertions, 4 deletions
diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp index f3d877eb26..0d33b408bd 100644 --- a/LibGUI/GTextEditor.cpp +++ b/LibGUI/GTextEditor.cpp @@ -379,6 +379,11 @@ void GTextEditor::keydown_event(GKeyEvent& event) return; } + if (event.modifiers() == Mod_Shift && event.key() == KeyCode::Key_Delete) { + delete_current_line(); + return; + } + if (event.key() == KeyCode::Key_Delete) { do_delete(); return; @@ -390,12 +395,24 @@ void GTextEditor::keydown_event(GKeyEvent& event) return GWidget::keydown_event(event); } +void GTextEditor::delete_current_line() +{ + if (has_selection()) + return delete_selection(); + + m_lines.remove(m_cursor.line()); + if (m_lines.is_empty()) + m_lines.append(make<Line>()); + + update_content_size(); + update(); +} + void GTextEditor::do_delete() { - if (has_selection()) { - delete_selection(); - return; - } + if (has_selection()) + return delete_selection(); + if (m_cursor.column() < current_line().length()) { // Delete within line current_line().remove(m_cursor.column()); diff --git a/LibGUI/GTextEditor.h b/LibGUI/GTextEditor.h index 9e5b88cf74..abc529b76f 100644 --- a/LibGUI/GTextEditor.h +++ b/LibGUI/GTextEditor.h @@ -94,6 +94,7 @@ public: void copy(); void paste(); void do_delete(); + void delete_current_line(); Function<void(GTextEditor&)> on_return_pressed; Function<void(GTextEditor&)> on_escape_pressed; |