1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:17:45 +00:00

LibGUI: Add Ctrl-W to insert mode

In Vim's insert mode, Ctrl-W deletes the word before the cursor, like
Ctrl-Backspace. Unlike Ctrl-Backspace, if only whitespace exists between
the end of the word and the cursor, the word will be deleted with the
whitespace.

To do so, this commit introduces two methods: delete_previous_word() for
TextEditor and first_word_before() for TextDocument, where the former
depends on the latter. delete_previous_word() is then called in
VimEditingEngine.
This commit is contained in:
Ariel Don 2021-07-13 22:12:07 -05:00 committed by Gunnar Beutner
parent 8f01a8b741
commit 808e5e813f
5 changed files with 52 additions and 0 deletions

View file

@ -794,6 +794,16 @@ bool VimEditingEngine::on_key_in_insert_mode(const KeyEvent& event)
if (EditingEngine::on_key(event))
return true;
if (event.ctrl()) {
switch (event.key()) {
case KeyCode::Key_W:
m_editor->delete_previous_word();
return true;
default:
break;
}
}
if (event.key() == KeyCode::Key_Escape || (event.ctrl() && event.key() == KeyCode::Key_LeftBracket) || (event.ctrl() && event.key() == KeyCode::Key_C)) {
if (m_editor->cursor().column() > 0)
move_one_left();