Browse Source

Make left/right keys go to start/end of selection if text is selected in TextField.

tags/v2.6.6
Andrew Belt 3 months ago
parent
commit
7032310da7
1 changed files with 12 additions and 4 deletions
  1. +12
    -4
      src/ui/TextField.cpp

+ 12
- 4
src/ui/TextField.cpp View File

@@ -160,8 +160,12 @@ void TextField::onSelectKey(const SelectKeyEvent& e) {
} }
// Left // Left
if (e.isKeyCommand(GLFW_KEY_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); e.consume(this);
} }
if (e.isKeyCommand(GLFW_KEY_LEFT, TEXTFIELD_MOD_CTRL)) { if (e.isKeyCommand(GLFW_KEY_LEFT, TEXTFIELD_MOD_CTRL)) {
@@ -179,8 +183,12 @@ void TextField::onSelectKey(const SelectKeyEvent& e) {
} }
// Right // Right
if (e.isKeyCommand(GLFW_KEY_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); e.consume(this);
} }
if (e.isKeyCommand(GLFW_KEY_RIGHT, TEXTFIELD_MOD_CTRL)) { if (e.isKeyCommand(GLFW_KEY_RIGHT, TEXTFIELD_MOD_CTRL)) {


Loading…
Cancel
Save