From 7032310da7615652918663f8b99b9bdfbc0c71d0 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 4 Nov 2025 02:08:09 -0500 Subject: [PATCH] Make left/right keys go to start/end of selection if text is selected in TextField. --- src/ui/TextField.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ui/TextField.cpp b/src/ui/TextField.cpp index 7507285c..0c831e47 100644 --- a/src/ui/TextField.cpp +++ b/src/ui/TextField.cpp @@ -160,8 +160,12 @@ void TextField::onSelectKey(const SelectKeyEvent& e) { } // Left if (e.isKeyCommand(GLFW_KEY_LEFT)) { - cursor = string::UTF8PrevCodepoint(text, cursor); - selection = cursor; + if (selection == cursor) { + selection = cursor = string::UTF8PrevCodepoint(text, cursor); + } + else { + selection = cursor = std::min(selection, cursor); + } e.consume(this); } if (e.isKeyCommand(GLFW_KEY_LEFT, TEXTFIELD_MOD_CTRL)) { @@ -179,8 +183,12 @@ void TextField::onSelectKey(const SelectKeyEvent& e) { } // Right if (e.isKeyCommand(GLFW_KEY_RIGHT)) { - cursor = string::UTF8NextCodepoint(text, cursor); - selection = cursor; + if (selection == cursor) { + selection = cursor = string::UTF8NextCodepoint(text, cursor); + } + else { + selection = cursor = std::max(selection, cursor); + } e.consume(this); } if (e.isKeyCommand(GLFW_KEY_RIGHT, TEXTFIELD_MOD_CTRL)) {