summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAriel Don <arieldn@protonmail.com>2021-07-15 16:35:45 -0500
committerGunnar Beutner <gunnar@beutner.name>2021-07-20 03:22:28 +0200
commit54bf6a7884f0c4a589e0b4d6f1ca96645b77fa5b (patch)
treef63d97be2f96cb899b130dcca9428d0a1f23c5db
parent8230bf89443781c7662e69dbd52457585ef4e7c2 (diff)
downloadserenity-54bf6a7884f0c4a589e0b4d6f1ca96645b77fa5b.zip
LibGUI: Add Ctrl-U to insert mode
While under insert mode, Ctrl-U deletes all characters between the first non-blank character of the line and the cursor. Implement delete_from_line_start_to_cursor() in TextEditor. Then, call the method in VimEditingEngine via its pointer to an instance of TextEditor.
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp7
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.h1
-rw-r--r--Userland/Libraries/LibGUI/VimEditingEngine.cpp3
3 files changed, 11 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index a1b2cc7074..eeafb357bf 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -928,6 +928,13 @@ void TextEditor::delete_previous_char()
execute<RemoveTextCommand>(document().text_in_range(to_erase), to_erase);
}
+void TextEditor::delete_from_line_start_to_cursor()
+{
+ TextPosition start(m_cursor.line(), current_line().first_non_whitespace_column());
+ TextRange to_erase(start, m_cursor);
+ execute<RemoveTextCommand>(document().text_in_range(to_erase), to_erase);
+}
+
void TextEditor::do_delete()
{
if (!is_editable())
diff --git a/Userland/Libraries/LibGUI/TextEditor.h b/Userland/Libraries/LibGUI/TextEditor.h
index 6e1a1c0e9b..cea1c30f25 100644
--- a/Userland/Libraries/LibGUI/TextEditor.h
+++ b/Userland/Libraries/LibGUI/TextEditor.h
@@ -137,6 +137,7 @@ public:
void delete_current_line();
void delete_previous_word();
void delete_previous_char();
+ void delete_from_line_start_to_cursor();
void select_all();
virtual void undo();
virtual void redo();
diff --git a/Userland/Libraries/LibGUI/VimEditingEngine.cpp b/Userland/Libraries/LibGUI/VimEditingEngine.cpp
index 1057373539..8dba8b8a47 100644
--- a/Userland/Libraries/LibGUI/VimEditingEngine.cpp
+++ b/Userland/Libraries/LibGUI/VimEditingEngine.cpp
@@ -802,6 +802,9 @@ bool VimEditingEngine::on_key_in_insert_mode(const KeyEvent& event)
case KeyCode::Key_H:
m_editor->delete_previous_char();
return true;
+ case KeyCode::Key_U:
+ m_editor->delete_from_line_start_to_cursor();
+ return true;
default:
break;
}