summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authorAndrew January <ajanuary@evertz.com>2021-08-20 19:08:34 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-13 12:53:29 +0100
commitc0d6e37ab378b6607f12a0ca4b8176afa1d1cec8 (patch)
tree47e64fe31db35b5aa5546eaf30b890a925a1f4ce /Userland/Libraries/LibGUI
parent22e80bae29781ac286cfc47deecccc6faac59d53 (diff)
downloadserenity-c0d6e37ab378b6607f12a0ca4b8176afa1d1cec8.zip
LibGUI: Add support for Ctrl+Delete in TextEditor
Allow deleting the word after the cursor using Ctrl+Delete in a similar manner to how Ctrl+Backspace deletes the word before the cursor.
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index 7eeebbe680..8ad2bd30dd 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -845,13 +845,22 @@ void TextEditor::keydown_event(KeyEvent& event)
if (m_cursor.column() < current_line().length()) {
// Delete within line
- TextRange erased_range(m_cursor, { m_cursor.line(), m_cursor.column() + 1 });
+ int erase_count = 1;
+ if (event.modifiers() == Mod_Ctrl) {
+ auto word_break_pos = document().first_word_break_after(m_cursor);
+ erase_count = word_break_pos.column() - m_cursor.column();
+ }
+ TextRange erased_range(m_cursor, { m_cursor.line(), m_cursor.column() + erase_count });
execute<RemoveTextCommand>(document().text_in_range(erased_range), erased_range);
return;
}
if (m_cursor.column() == current_line().length() && m_cursor.line() != line_count() - 1) {
// Delete at end of line; merge with next line
- TextRange erased_range(m_cursor, { m_cursor.line() + 1, 0 });
+ size_t erase_count = 0;
+ if (event.modifiers() == Mod_Ctrl) {
+ erase_count = document().first_word_break_after({ m_cursor.line() + 1, 0 }).column();
+ }
+ TextRange erased_range(m_cursor, { m_cursor.line() + 1, erase_count });
execute<RemoveTextCommand>(document().text_in_range(erased_range), erased_range);
return;
}