Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlxInputText improvements #257

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}