summaryrefslogtreecommitdiff
path: root/LibGUI/GTextEditor.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-08 14:10:34 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-08 14:10:34 +0100
commit220c7b5f75c48f4e0dee432221e8047826d0667c (patch)
tree026328faf5dff2bb282e651cc1fb7a2caaed5599 /LibGUI/GTextEditor.cpp
parent48d48679b0475d525db9bc644acd3157d4117f69 (diff)
downloadserenity-220c7b5f75c48f4e0dee432221e8047826d0667c.zip
GTextEditor: Replace selection on input or Backspace/Delete.
Diffstat (limited to 'LibGUI/GTextEditor.cpp')
-rw-r--r--LibGUI/GTextEditor.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp
index 696bd80c5e..9feb0315c9 100644
--- a/LibGUI/GTextEditor.cpp
+++ b/LibGUI/GTextEditor.cpp
@@ -296,6 +296,10 @@ void GTextEditor::keydown_event(GKeyEvent& event)
}
if (!event.modifiers() && event.key() == KeyCode::Key_Backspace) {
+ if (has_selection()) {
+ delete_selection();
+ return;
+ }
if (m_cursor.column() > 0) {
// Backspace within line
current_line().remove(m_cursor.column() - 1);
@@ -318,6 +322,10 @@ void GTextEditor::keydown_event(GKeyEvent& event)
}
if (!event.modifiers() && 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());
@@ -339,8 +347,8 @@ void GTextEditor::keydown_event(GKeyEvent& event)
return;
}
- if (!event.text().is_empty())
- insert_at_cursor(event.text()[0]);
+ if (!event.ctrl() && !event.alt() && !event.text().is_empty())
+ insert_at_cursor_or_replace_selection(event.text());
return GWidget::keydown_event(event);
}