Skip to content

Commit 2fd4abc

Browse files
[hui] Fixed text input autofocus
1 parent e934a3f commit 2fd4abc

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

hrt/ui/HuiInputBox.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class HuiInputBox extends HuiElement {
4646
textInput.onChange = onChangeInternal;
4747
}
4848

49-
public function focus() {
50-
textInput.focus();
49+
public function focus(autoSelect = true) {
50+
textInput.focus(autoSelect);
5151
}
5252

5353
function afterReflow() {

hrt/ui/HuiTextInput.hx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ class HuiTextInput extends h2d.TextInput implements h2d.domkit.Object {
2121
smooth = true;
2222
}
2323

24+
override public function focus( autoSelect=true ) {
25+
interactive.focus();
26+
if( cursorIndex < 0 ) {
27+
cursorIndex = getTextLength();
28+
}
29+
if( autoSelect && text != "" && !multiline ) selectionRange = { start : 0, length : getTextLength() };
30+
}
31+
2432

2533
function set_baseFont(v : String) {
2634
font = HuiText.loadFontStatic(v);

0 commit comments

Comments
 (0)