added functionality for keys Home and End in TextBox.cpp (#541)

* added functionality for keys Home and End in TextBox.cpp

* fixed mistakes

* fixed selection

* deleted comments with code

* replaced tabs on spaces
This commit is contained in:
RomanDonw 2025-07-13 19:54:46 +10:00 committed by GitHub
parent aca9b49c77
commit 6a7a3fc293
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -829,6 +829,10 @@ void TextBox::onInput() {
void TextBox::performEditingKeyboardEvents(Keycode key) {
bool shiftPressed = gui.getInput().pressed(Keycode::LEFT_SHIFT);
bool breakSelection = getSelectionLength() != 0 && !shiftPressed;
uint current_line = getLineAt(getCaret());
uint previousCaret = getCaret();
if (key == Keycode::BACKSPACE) {
bool erased = eraseSelected();
if (erased) {
@ -873,6 +877,30 @@ void TextBox::performEditingKeyboardEvents(Keycode key) {
onUpPressed();
} else if (key == Keycode::DOWN && onDownPressed) {
onDownPressed();
} else if (key == Keycode::HOME) {
setCaret(getLinePos(current_line));
resetMaxLocalCaret();
if (shiftPressed) {
if (selectionStart == selectionEnd) {
selectionOrigin = previousCaret;
}
extendSelection(getCaret());
} else {
resetSelection();
}
} else if (key == Keycode::END && getLineLength(current_line) > 0) {
setCaret(getLinePos(current_line) + getLineLength(current_line) - 1);
resetMaxLocalCaret();
if (shiftPressed) {
if (selectionStart == selectionEnd) {
selectionOrigin = previousCaret;
}
extendSelection(getCaret());
} else {
resetSelection();
}
}
}