Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10497] iOS: Insert text at current cursor position

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2014-04-08T20:58:06.000+0000
Affected Version/sRelease 2.1.0
Fix Version/s2014 Sprint 07, 2014 Sprint 07 SDK, Release 3.3.0
ComponentsiOS
Labelsapi, module_textarea, module_textfield, qe-closed-3.3.0, qe-testadded
ReporterMarkus Wutzler
AssigneeVishal Duggal
Created2012-08-06T01:57:09.000+0000
Updated2014-04-24T09:26:58.000+0000

Description

I've tried several different ways to insert text at current cursor position but there are two major problems. First there is no possibility to get the current cursor position. On iOS there is a possibility to track this position with _change_ and _selected_ events but this is rather defective. Second problem is that (if you've inserted at correct position) the cursor will be set to the end of the text on iOS (I didn't tried on Android. Usecase: In some kind of Twitter Application i wanna provide a '#' and a '@' button for faster writing a message.

Comments

  1. Gabriel Lin 2012-08-30

    I really need this featureļ¼Œhope you can fix it in next version!
  2. Walter Zeidler 2012-09-29

    I really need this feature, too for a implementation of a Texteditor under iOS. Thank you for solve this.
  3. Markus Wutzler 2012-09-29

    Yes, we need it also. We're now planning to release our app without this feature. This is bad for our customers but we didn't find a useful solution till today.
  4. Vitr 2013-07-04

    We are talking about a TextArea - aren't we? I would need that feature, too! Is there at least a way to get the current cursor position, so I can scroll the containing scrollview to this position programmatically?
  5. Markus Wutzler 2013-08-16

    No solution / workaround yet. :-( Only native extension possible yet.
  6. Hagen Nordheim 2013-09-30

    Are there any updates on this issue?
  7. Hagen Nordheim 2014-01-13

    So, will this issue be resolved by 10/Feb/14?
  8. Vishal Duggal 2014-04-01

    Exposed property selection on TextArea and TextField to get current cursor characteristics on iOS and Android. We already have support for setSelection(start,end) on iOS and Android. Test Case
       var win = Ti.UI.createWindow({backgroundColor:'white',layout:'vertical',fullscreen:true});
       
       var control = Ti.UI.createView({width:Ti.UI.SIZE,height:Ti.UI.SIZE,layout:'horizontal'});
       
       var b1 = Ti.UI.createButton({title:'TEXTFIELD',right:10});
       var b2 = Ti.UI.createButton({title:'TEXTAREA',left:10});
       control.add(b1);
       control.add(b2);
       var textField = Ti.UI.createTextField({top:10,height:40, width:Ti.UI.FILL, value:'I am a text field'});
       var textArea = Ti.UI.createTextArea({top:10,height:40, width:Ti.UI.FILL, value: 'I am a text area'});
       win.add(control);
       win.add(textField);
       win.add(textArea);
       win.open();
       
       b1.addEventListener('click',function(e){
           Ti.API.info('\n\n****************');
           Ti.API.info('TEXTFIELD');
           var result = textField.selection;
           if(result == null || result == undefined) {
               Ti.API.info('NO selection info available from property');
           } else {
               Ti.API.info('PROPERTY selection start:'+result.location+' length:'+result.length);
           }
           
           var result1 = textField.getSelection();
           if(result1 == null || result1 == undefined) {
               Ti.API.info('NO selection info available from method');
           } else {
               Ti.API.info('METHOD selection start:'+result1.location+' length:'+result1.length);
           }
           Ti.API.info('****************');
       })
       
       
       b2.addEventListener('click',function(e){
           Ti.API.info('\n\n----------------------');
           Ti.API.info('TEXTAREA');
           var result = textArea.selection;
           if(result == null || result == undefined) {
               Ti.API.info('NO selection info available from property');
           } else {
               Ti.API.info('PROPERTY selection start:'+result.location+' length:'+result.length);
           }
           
           var result1 = textArea.getSelection();
           if(result1 == null || result1 == undefined) {
               Ti.API.info('NO selection info available from method');
           } else {
               Ti.API.info('METHOD selection start:'+result1.location+' length:'+result1.length);
           }
           Ti.API.info('----------------------');
       })
       
  9. Vishal Duggal 2014-04-01

    Pull pending against master https://github.com/appcelerator/titanium_mobile/pull/5568
  10. Neha Mittal 2014-04-23

    Verified fix with below environment: Appc Studio: 3.3.0.201404211130 SDK build: 3.3.0.v20140422163054 acs: 1.0.14 npm: 1.3.2 alloy: 1.4.0-dev CLI: titanium-3.3.0-dev titanium-code-processor:1.1.1-beta1 Xcode: 5.1.1 Osx: Mavericks(10.9.2) Device: iPhone 5C( iOS 7.1) and Galaxy Nexus (4.1) Able to insert text at the current location in both TextField and TextArea. Hence Closing the issue.

JSON Source