Skip to content

Commit

Permalink
FlxInputText improvements (#257)
Browse files Browse the repository at this point in the history
* Update FlxInputText.hx

* Update FlxInputText.hx
  • Loading branch information
DigiEggz authored Oct 18, 2023
1 parent dfff192 commit 440210f
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions flixel/addons/ui/FlxInputText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import flixel.util.FlxColor;
import flixel.util.FlxDestroyUtil;
import flixel.util.FlxTimer;
import lime.system.Clipboard;
#if (html5 && js)
import lime.app.Application;
#end

/**
* FlxInputText v1.11, ported to Haxe
Expand Down Expand Up @@ -236,9 +233,8 @@ class FlxInputText extends FlxText
}

// Register paste events for the HTML5 parent window
#if (html5 && js)
var window = Application.current.window;
@:privateAccess window.onTextInput.add(handleClipboardText);
#if (js && html5)
FlxG.stage.window.onTextInput.add(handleClipboardText);
#end

text = Text; // ensure set_text is called to avoid bugs (like not preparing _charBoundaries on sys target, making it impossible to click)
Expand Down Expand Up @@ -268,9 +264,8 @@ class FlxInputText extends FlxText
}
#end

#if (html5 && js)
var window = Application.current.window;
@:privateAccess window.onTextInput.remove(handleClipboardText);
#if (js && html5)
FlxG.stage.window.onTextInput.remove(handleClipboardText);
#end

super.destroy();
Expand Down Expand Up @@ -386,9 +381,8 @@ class FlxInputText extends FlxText
onChange(ENTER_ACTION);
case V if (e.ctrlKey):
// Reapply focus when tabbing back into the window and selecting the field
#if (html5 && js)
var window = Application.current.window;
@:privateAccess window.textInputEnabled = true;
#if (js && html5)
FlxG.stage.window.textInputEnabled = true;
#else
var clipboardText:String = Clipboard.text;
if (clipboardText != null)
Expand Down Expand Up @@ -832,6 +826,11 @@ class FlxInputText extends FlxText
_caretTimer = new FlxTimer().start(0.5, toggleCaret, 0);
caret.visible = true;
caretIndex = text.length;

#if mobile
// Initialize soft keyboard
FlxG.stage.window.textInputEnabled = true;
#end
}
}
else
Expand All @@ -842,15 +841,20 @@ class FlxInputText extends FlxText
{
_caretTimer.cancel();
}

#if mobile
// Remove soft keyboard
FlxG.stage.window.textInputEnabled = false;
#end
}

if (newFocus != hasFocus)
{
calcFrame();

// Set focus on background parent text input
#if (html5 && js)
var window = Application.current.window;
#if (js && html5)
var window = FlxG.stage.window;
@:privateAccess window.__backend.setTextInputEnabled(newFocus);
#end
}
Expand Down Expand Up @@ -1030,4 +1034,4 @@ class FlxInputText extends FlxText
calcFrame();
return backgroundColor;
}
}
}

0 comments on commit 440210f

Please sign in to comment.