From 5c495b987bba765e1a7723001be76da629c6a889 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 25 Mar 2021 21:14:37 +0100 Subject: [PATCH] Add Shift+Home shortcut to Text Boxes #386 --- Source/Engine/UI/GUI/Common/TextBoxBase.cs | 33 +++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/TextBoxBase.cs b/Source/Engine/UI/GUI/Common/TextBoxBase.cs index 5541ee3e5..2e4ef51e3 100644 --- a/Source/Engine/UI/GUI/Common/TextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/TextBoxBase.cs @@ -812,6 +812,19 @@ namespace FlaxEngine.GUI return spaceLoc; } + private int FindPrevLineBegin() + { + int caretPos = CaretPosition; + if (caretPos - 2 < 0) + return 0; + int newLineLoc = _text.LastIndexOf('\n', caretPos - 2); + if (newLineLoc == -1) + newLineLoc = 0; + else + newLineLoc++; + return newLineLoc; + } + private int FindLineDownChar(int index) { if (!IsMultiline) @@ -1181,7 +1194,6 @@ namespace FlaxEngine.GUI return true; } case KeyboardKeys.Return: - { if (IsMultiline) { // Insert new line @@ -1192,15 +1204,22 @@ namespace FlaxEngine.GUI // End editing Defocus(); } - return true; - } case KeyboardKeys.Home: - { - // Move caret to the first character - SetSelection(0); + if (shiftDown) + { + // Select text from the current cursor point back to the beginning of the line + if (_selectionStart != -1) + { + SetSelection(FindPrevLineBegin(), _selectionStart); + } + } + else + { + // Move caret to the first character + SetSelection(0); + } return true; - } case KeyboardKeys.End: { // Move caret after last character