diff --git a/src/frontend/gui/controls.cpp b/src/frontend/gui/controls.cpp index 9b29c6b1..a68830be 100644 --- a/src/frontend/gui/controls.cpp +++ b/src/frontend/gui/controls.cpp @@ -514,10 +514,7 @@ void TextBox::keyPressed(int key) { // Select/deselect all if (key == keycode::A) { if (selectionStart == selectionEnd) { - selectionStart = 0; - selectionEnd = input.length(); - selectionOrigin = 0; - setCaret(selectionEnd); + select(0, input.length()); } else { resetSelection(); } @@ -525,6 +522,19 @@ void TextBox::keyPressed(int key) { } } +void TextBox::select(int start, int end) { + if (end < start) { + std::swap(start, end); + } + start = normalizeIndex(start); + end = normalizeIndex(end); + + selectionStart = start; + selectionEnd = end; + selectionOrigin = start; + setCaret(selectionEnd); +} + std::shared_ptr TextBox::getAt(glm::vec2 pos, std::shared_ptr self) { return UINode::getAt(pos, self); } diff --git a/src/frontend/gui/controls.h b/src/frontend/gui/controls.h index 2452992b..9e2219b9 100644 --- a/src/frontend/gui/controls.h +++ b/src/frontend/gui/controls.h @@ -157,6 +157,7 @@ namespace gui { virtual std::wstring getSelection() const; virtual uint getCaret() const; virtual void setCaret(uint position); + virtual void select(int start, int end); virtual bool validate(); virtual void setValid(bool valid); virtual bool isValid() const;