1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:58:11 +00:00

LibGUI: Add shortcut for inserting new line

This adds shortcut for inserting a new empty indented line
above/below current cursor position.

- <Ctrl-Return> for inserting line below.
- <Ctrl-Shift-Return> for inserting line above.
This commit is contained in:
Snow 2022-12-02 16:14:57 +08:00 committed by Sam Atkins
parent e06f9174a1
commit 2f8c7b1b30
3 changed files with 81 additions and 0 deletions

View file

@ -890,6 +890,17 @@ void TextEditor::keydown_event(KeyEvent& event)
try_update_autocomplete();
} };
if (is_multi_line() && !event.alt() && event.ctrl() && event.key() == KeyCode::Key_Return) {
if (!is_editable())
return;
size_t indent_length = current_line().leading_spaces();
DeprecatedString indent = current_line().to_utf8().substring(0, indent_length);
auto insert_pos = event.shift() ? InsertLineCommand::InsertPosition::Above : InsertLineCommand::InsertPosition::Below;
execute<InsertLineCommand>(m_cursor, move(indent), insert_pos);
return;
}
if (is_multi_line() && !event.shift() && !event.alt() && event.ctrl() && event.key() == KeyCode::Key_Space) {
if (m_autocomplete_provider) {
try_show_autocomplete(UserRequestedAutocomplete::Yes);