Skip to content

Commit

Permalink
LibGUI: Add support for Ctrl+Delete in TextEditor
Browse files Browse the repository at this point in the history
Allow deleting the word after the cursor using Ctrl+Delete in a similar
manner to how Ctrl+Backspace deletes the word before the cursor.
  • Loading branch information
aJanuary authored and awesomekling committed Nov 13, 2021
1 parent 22e80ba commit c0d6e37
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Userland/Libraries/LibGUI/TextEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c0d6e37

Please sign in to comment.