feathersui-starling
feathersui-starling copied to clipboard
TextInput selectionBeginIndex always returns -1 on iOS
I used another implementation of StageText before and the selectionAnchorIndex was working. TextInput seems to work fine on desktop though.
I cannot reproduce this issue. With the following code and AIR 23, the initial selectionBeginIndex and selectionEndIndex are 0. On focus, they may change to a different value, but they are never -1.
var input:TextInput = new TextInput();
input.text = "Sample Text";
input.move(40, 40);
input.addEventListener(FeathersEventType.FOCUS_IN, function():void
{
trace(input.selectionBeginIndex, input.selectionEndIndex);
});
this.addChild(input);
trace(input.selectionBeginIndex, input.selectionEndIndex);
True, when the input is focused, the values are correct. But listen to the change event and run on iOS.
Here's my input:
var input:TextInput = new TextInput();
input.text = "Sample Text";
input.textEditorProperties.fontSize = 30;
input.width = 300;
input.height = 100;
input.move(100, 100);
input.addEventListener(FeathersEventType.FOCUS_IN, function(event:Event):void {
trace("FOCUS_IN", input.text, input.selectionBeginIndex, input.selectionEndIndex);
});
input.addEventListener(Event.CHANGE, function(event:Event):void {
trace("CHANGE", input.text, input.selectionBeginIndex, input.selectionEndIndex);
});
addChild(input);
And here's my output when running on iOS:
[trace] FOCUS_IN Sample Text 11 11
[trace] CHANGE Sample TextN -1 -1
[trace] CHANGE Sample TextNe -1 -1
[trace] CHANGE Sample TextNew -1 -1
[trace] CHANGE Sample TextNewT -1 -1
[trace] CHANGE Sample TextNewTe -1 -1
[trace] CHANGE Sample TextNewTex -1 -1
[trace] CHANGE Sample TextNewText -1 -1
[trace] CHANGE Sample ITextNewText -1 -1
[trace] CHANGE Sample InTextNewText -1 -1
[trace] CHANGE Sample InBTextNewText -1 -1
[trace] CHANGE Sample InBeTextNewText -1 -1
[trace] CHANGE Sample InBetTextNewText -1 -1
[trace] CHANGE Sample InBetwTextNewText -1 -1
[trace] CHANGE Sample InBetweTextNewText -1 -1
[trace] CHANGE Sample InBetweeTextNewText -1 -1
[trace] CHANGE Sample InBetweenTextNewText -1 -1
Thanks! That was the extra information that I needed.
It looks like the selectionAnchorIndex and selectionActiveIndex properties on StageText are returning -1. This is an AIR bug.
The following code is able to reproduce this issue with StageText only:
var x:Number = 10;
var y:Number = 10;
var w:Number = 200;
var h:Number = 100;
this.graphics.beginFill(0xcccccc);
this.graphics.drawRect(x, y, w, h);
this.graphics.endFill();
var stageText:StageText = new StageText();
stageText.text = "Hello World";
stageText.fontSize = 20;
stageText.viewPort = new Rectangle(x, y, w, h);
stageText.stage = stage;
stageText.addEventListener(Event.CHANGE, function(event:Event):void
{
trace("StageText Event.CHANGE");
trace("selectionAnchorIndex:", stageText.selectionAnchorIndex, stageText.selectionActiveIndex);
});
I opened a bug report with Adobe: #4197297
I received the following response:
As per the documentation at http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/StageText.html These properties are not supported for non-multiline StageText objects and return -1. Please try with multiline StageText and you should see the correct value.
Thanks, Adobe AIR Team
It looks like that's the expected behavior, for some strange reason. Maybe iOS doesn't properly expose this information, or something.
Interesting... Hope they'll add it on their to-do list!