Add Shift+Home shortcut to Text Boxes

#386
This commit is contained in:
Wojtek Figat
2021-03-25 21:14:37 +01:00
parent 2b741cae58
commit 5c495b987b

View File

@@ -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