Skip to content

Commit 13e6b9a

Browse files
committed
Fix UITextBox Text Input
1 parent 2e7a8dc commit 13e6b9a

1 file changed

Lines changed: 36 additions & 30 deletions

File tree

source/funkin/editors/ui/UITextBox.hx

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
7272
framesOffset = (selected ? 18 : (hovered ? 9 : 0));
7373
@:privateAccess {
7474
if (selected) {
75-
__wasFocused = true;
75+
if (!__wasFocused) {
76+
__wasFocused = true;
77+
FlxG.stage.window.textInputEnabled = true;
78+
}
7679
caretSpr.alpha = (FlxG.game.ticks % 666) >= 333 ? 1 : 0;
7780

7881
var curPos = switch (position) {
@@ -92,6 +95,7 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
9295
} else {
9396
if (__wasFocused) {
9497
__wasFocused = false;
98+
FlxG.stage.window.textInputEnabled = false;
9599
if (onChange != null)
96100
onChange(label.text);
97101
}
@@ -133,6 +137,7 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
133137
focused = false;
134138
if (onChange != null)
135139
onChange(label.text);
140+
return;
136141
case LEFT:
137142
if (modifier.ctrlKey) {
138143
if (position == 0)
@@ -149,6 +154,7 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
149154
}
150155

151156
changeSelection(-1);
157+
return;
152158
case RIGHT:
153159
if (modifier.ctrlKey) {
154160
if (position == label.text.length)
@@ -165,6 +171,7 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
165171
}
166172

167173
changeSelection(1);
174+
return;
168175
case BACKSPACE:
169176
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_TEXTREMOVE_SOUND));
170177

@@ -181,6 +188,7 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
181188
label.text = label.text.substr(0, position - 1) + label.text.substr(position);
182189
changeSelection(-1);
183190
}
191+
return;
184192
case DELETE:
185193
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_TEXTREMOVE_SOUND));
186194

@@ -196,48 +204,46 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
196204
if (position < label.text.length) {
197205
label.text = label.text.substr(0, position) + label.text.substr(position + 1);
198206
}
207+
return;
199208
case HOME:
200209
position = 0;
210+
return;
201211
case END:
202212
position = label.text.length;
213+
return;
203214
case V:
204-
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_PASTE_SOUND));
205-
// Hey lj here, fixed copying because before we checked if the modifier was left or right ctrl
206-
// but somehow it gave a int outside of the KeyModifier's range :sob:
207-
// apparently there is a boolean that just checks for you. yw :D
215+
if (modifier.ctrlKey) {
216+
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_PASTE_SOUND));
208217

209-
// if we are not holding ctrl, ignore
210-
if (!modifier.ctrlKey)
211-
return;
212-
// we pasting
213-
var data:String = Clipboard.generalClipboard.getData(TEXT_FORMAT);
214-
if (data != null)
215-
onTextInput(data);
218+
// Hey lj here, fixed copying because before we checked if the modifier was left or right ctrl
219+
// but somehow it gave a int outside of the KeyModifier's range :sob:
220+
// apparently there is a boolean that just checks for you. yw :D
221+
222+
// we pasting
223+
var data:String = Clipboard.generalClipboard.getData(TEXT_FORMAT);
224+
if (data != null)
225+
onTextInput(data);
226+
}
216227
case C:
217-
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_COPY_SOUND));
218-
// if we are not holding ctrl, ignore
219-
if (!modifier.ctrlKey)
220-
return;
228+
if (modifier.ctrlKey) {
229+
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_COPY_SOUND));
221230

222-
// copying
223-
Clipboard.generalClipboard.setData(TEXT_FORMAT, label.text);
231+
Clipboard.generalClipboard.setData(TEXT_FORMAT, label.text);
232+
}
224233
case X:
225-
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_CUT_SOUND));
234+
if (modifier.ctrlKey) {
235+
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_CUT_SOUND));
226236

227-
// if we are not holding ctrl, ignore
228-
if (!modifier.ctrlKey)
237+
Clipboard.generalClipboard.setData(TEXT_FORMAT, label.text);
238+
position = 0;
239+
label.text = "";
229240
return;
230-
231-
// cutting
232-
Clipboard.generalClipboard.setData(TEXT_FORMAT, label.text);
233-
position = 0;
234-
label.text = "";
241+
}
235242
default:
236-
if (modifier.ctrlKey || modifier.altKey || modifier.shiftKey)
237-
return;
238-
239-
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_TEXTTYPE_SOUND));
240243
}
244+
245+
if (modifier.ctrlKey || modifier.altKey || modifier.shiftKey) return;
246+
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_TEXTTYPE_SOUND));
241247
}
242248

243249
public function changeSelection(change:Int) {

0 commit comments

Comments
 (0)