[TIMOB-19639] Android: TextField setSelection(0,end) has to be called twice to select text
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-04-22T16:31:01.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 5.4.0 |
Components | Android |
Labels | android, selection, textfield |
Reporter | Michael Gangolf |
Assignee | Hans Knöchel |
Created | 2015-09-24T08:16:55.000+0000 |
Updated | 2016-06-28T23:14:18.000+0000 |
Description
When trying to select the whole text in a TextField I use the setSelection function:
function selectText(e){
$.tf_1.setSelection(0,$.tf_1.value.length)
}
$.btn.addEventListener("click",selectText)
$.index.open();
<Alloy>
<Window class="container">
<TextField id="tf_1" value="123456"></TextField>
<Button id="btn">Select text</Button>
</Window>
</Alloy>
{noformat}
"TextField": {
right:50,
left:50,
color:"black"
}
".container": {
layout:"vertical",
backgroundColor:"white"
}
{noformat}
It's only working when the cursor is at the beginning. When it's in the middle or end it will just move the cursor to front and I have to click the button again to select the text.
From the function call (0, length) I expect to start from 0 and select the whole text in one go
Android 5 (Nexus 4)
SDK 5.0.0.GA
_Workaround:_
use
function selectText(e){
$.tf_1.setSelection(0,$.tf_1.value.length)
_.delay(function(){
$.tf_1.setSelection(0,$.tf_1.value.length)
},200);
}
PR: https://github.com/appcelerator/titanium_mobile/pull/7905 Bug caused by IME (input method editor), see: http://stackoverflow.com/a/35527348/5193915
[~michael] The PR looks great! Can you provide a demo code that can be ran without Alloy? I can create one if it exceeds your available time, just let me know.
no problem:
*Steps to reproduce* * Click inside the textview so the cursor is not in front * Click a button to set the selection *without the patch* cursor moves to the beginnen, no selection. You have to press the button again (it will change the cursor from "selection cursor" to the normal one) *with the patch* text gets selected
Approved! Thank you [~michael], great work!
Verified the fix. Closing. Environment: Appc Studio : 4.7.0.201606150733 Ti SDK : 5.4.0.v20160617074028 Ti CLI : 5.0.9 Alloy : 1.9.0 MAC El Capitan : 10.11.4 Appc NPM : 4.2.7-2 Appc CLI : 5.4.0-20 Node: 4.4.4 Nexus 6 - Android 6.0.1