Fix UITextBox Text Input

This commit is contained in:
Ralty
2026-03-02 21:20:52 +07:00
parent 2e7a8dcd21
commit 13e6b9a56f
+36 -30
View File
@@ -72,7 +72,10 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
framesOffset = (selected ? 18 : (hovered ? 9 : 0));
@:privateAccess {
if (selected) {
__wasFocused = true;
if (!__wasFocused) {
__wasFocused = true;
FlxG.stage.window.textInputEnabled = true;
}
caretSpr.alpha = (FlxG.game.ticks % 666) >= 333 ? 1 : 0;
var curPos = switch (position) {
@@ -92,6 +95,7 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
} else {
if (__wasFocused) {
__wasFocused = false;
FlxG.stage.window.textInputEnabled = false;
if (onChange != null)
onChange(label.text);
}
@@ -133,6 +137,7 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
focused = false;
if (onChange != null)
onChange(label.text);
return;
case LEFT:
if (modifier.ctrlKey) {
if (position == 0)
@@ -149,6 +154,7 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
}
changeSelection(-1);
return;
case RIGHT:
if (modifier.ctrlKey) {
if (position == label.text.length)
@@ -165,6 +171,7 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
}
changeSelection(1);
return;
case BACKSPACE:
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_TEXTREMOVE_SOUND));
@@ -181,6 +188,7 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
label.text = label.text.substr(0, position - 1) + label.text.substr(position);
changeSelection(-1);
}
return;
case DELETE:
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_TEXTREMOVE_SOUND));
@@ -196,48 +204,46 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
if (position < label.text.length) {
label.text = label.text.substr(0, position) + label.text.substr(position + 1);
}
return;
case HOME:
position = 0;
return;
case END:
position = label.text.length;
return;
case V:
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_PASTE_SOUND));
// Hey lj here, fixed copying because before we checked if the modifier was left or right ctrl
// but somehow it gave a int outside of the KeyModifier's range :sob:
// apparently there is a boolean that just checks for you. yw :D
if (modifier.ctrlKey) {
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_PASTE_SOUND));
// if we are not holding ctrl, ignore
if (!modifier.ctrlKey)
return;
// we pasting
var data:String = Clipboard.generalClipboard.getData(TEXT_FORMAT);
if (data != null)
onTextInput(data);
// Hey lj here, fixed copying because before we checked if the modifier was left or right ctrl
// but somehow it gave a int outside of the KeyModifier's range :sob:
// apparently there is a boolean that just checks for you. yw :D
// we pasting
var data:String = Clipboard.generalClipboard.getData(TEXT_FORMAT);
if (data != null)
onTextInput(data);
}
case C:
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_COPY_SOUND));
// if we are not holding ctrl, ignore
if (!modifier.ctrlKey)
return;
if (modifier.ctrlKey) {
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_COPY_SOUND));
// copying
Clipboard.generalClipboard.setData(TEXT_FORMAT, label.text);
Clipboard.generalClipboard.setData(TEXT_FORMAT, label.text);
}
case X:
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_CUT_SOUND));
if (modifier.ctrlKey) {
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_CUT_SOUND));
// if we are not holding ctrl, ignore
if (!modifier.ctrlKey)
Clipboard.generalClipboard.setData(TEXT_FORMAT, label.text);
position = 0;
label.text = "";
return;
// cutting
Clipboard.generalClipboard.setData(TEXT_FORMAT, label.text);
position = 0;
label.text = "";
}
default:
if (modifier.ctrlKey || modifier.altKey || modifier.shiftKey)
return;
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_TEXTTYPE_SOUND));
}
if (modifier.ctrlKey || modifier.altKey || modifier.shiftKey) return;
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_TEXTTYPE_SOUND));
}
public function changeSelection(change:Int) {