From c0d6e37ab378b6607f12a0ca4b8176afa1d1cec8 Mon Sep 17 00:00:00 2001 From: Andrew January Date: Fri, 20 Aug 2021 19:08:34 +0100 Subject: 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. --- Userland/Libraries/LibGUI/TextEditor.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'Userland/Libraries/LibGUI') 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(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(document().text_in_range(erased_range), erased_range); return; } -- cgit v1.2.3