From 6a7a3fc293dc30fdb041a8d07dccc1f85285a983 Mon Sep 17 00:00:00 2001 From: RomanDonw <126128023+RomanDonw@users.noreply.github.com> Date: Sun, 13 Jul 2025 19:54:46 +1000 Subject: [PATCH] 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 --- src/graphics/ui/elements/TextBox.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/graphics/ui/elements/TextBox.cpp b/src/graphics/ui/elements/TextBox.cpp index 9a9177f9..0ed75882 100644 --- a/src/graphics/ui/elements/TextBox.cpp +++ b/src/graphics/ui/elements/TextBox.cpp @@ -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(); + } } }