mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 02:55:07 +00:00
GTextEditor: Replace selection on input or Backspace/Delete.
This commit is contained in:
parent
48d48679b0
commit
220c7b5f75
1 changed files with 10 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue