Struggling with the native Text Box and the IOS Clipboard

When we adopted CSDK for our research development on devices there was one feature on my list that I could not find.  Copy and paste of text.  I didn’t see any easy way to do it when I reviewed CSDK for our development team.  That was last summer and we’re pretty committed now.

I am working on a project with TTU and College of Charleston and they need copy and paste of selected text.  After searching for a little less than a week, I cannot find a way to do this in CSDK without the use of native text boxes.  There is a deafening silence of any recent posts on the issue.

What is the state of copy and paste to the IOS clipboard in CSDK?

So far I have not been able to get native text boxes to work on the actual device.  I’d like to simulate an overlay. Works on the simulator but not on the device.  We are developing for iPad and iPod.  Two year old posts indicate that native text boxes don’t work on Android and that scaling is a big issue.

I need one of two solutions:

  1.  A way to copy text to the clipboard using CSDK display objects.

  2.  A way to get a consistent size and performance for a native text box on an overlay or a simulated overlay.

Any thoughts would be very much appreciated.

To be clear, I don’t need pasting ability.  I just need to get selected text onto the device clipboard for use in other apps.

Maybe you have already seen the pasteboard plugin, but I figured I’d post about it to be sure.

When you’re talking about copying display objects, are you talking about display.newText objects, or images and textures?

Yes.  I am aware of the pasteboard plugin.  That puts the text on the clipboard once it has been selected and copied.  My problem is with selecting and copying. This functionality will be needed again I’m sure.  But I’ll describe this specific use case.

I have a display.newText object with about 40 lines of text.  They are algebraic functions:

2x+3

4(x^2-6x) +7

Students need to be able to select a function or a few functions and copy them onto the clipboard for use in Geogebra, Numbers, etc.  They are currently displayed in a widget.newScrollView object.  Select and copy within the scrollView window would be ideal, but I plan to pop out an overlay that allows students to copy and paste.  I haven’t been able to get native.textBox to work yet in an overlay even though it just sits on top of everything.

The pasteboard plugin will be used to push the selected text onto the IOS clipboard.  That part is working fine.

Sorry about that Scot, I wasn’t looking at the initial intent of your post. My bad.

More to the point, you might get some use out of the http://widgetstown.com site, which has a lot of modified native. code for Corona projects.

Thanks for the link.  widgetstown.com is just as strangely silent about the native.newTextBox widget as Corona Labs.  Wonder what the huge mystery is?  Seems pretty basic.

At this point I may just use a jack hammer to fasten a screw.  I could iterate over the text and create 40 display.newText objects and have a listener on each one that adds it to the clipboard.  Any other thoughts would be much appreciated.

If you’re looking to hightlight a portion of a display.newText object and copy only that portion you’re going to have a very hard time (and it’s likely impossible), because newText objects are rendered as images on the OpenGL canvas, so native-style hightlighting is not possible. (Somebody correct me if I’m wrong.)

I think since you don’t need the highlighted portion to be user-selectable (since they will need to copy the entire equation), your strategy of separating each line of text into a new newText object and adding a listener to copy the tapped object’s “.text” value is probably your best bet. And the “glass half full” way to look at it is that you don’t run the risk of the user accidentally missing part of the equation by under- or over-highlighting. This method gives you more control over what gets copied to the clipboard.

An interesting situation, for certain. I think this thread will be useful for other devs down the road. Good luck!

@schroederapps:

Thanks.  It is the direction I’m headed at the moment.  

BTW: I was able to approximate text selection using the touch event move phase by estimating the the location of the substring to copy based upon the location and width of the newText object.  It might be possible to create text selection that way.  I would have to usea Rect object to highlight.  Not worth doing for this  project.

Been writing code since the Timex Sinclair days.  Using the open GL canvas is no excuse for the lack of select and copy since all text is eventually rendered as a bitmap for display and the engine needs to know where to place the letter bitmaps.  To be clear, I recognize and support the design decisions Corona engineers have made.  I am just saying that they could, if it was a priority, develop select and copy.

Maybe you have already seen the pasteboard plugin, but I figured I’d post about it to be sure.

When you’re talking about copying display objects, are you talking about display.newText objects, or images and textures?

Yes.  I am aware of the pasteboard plugin.  That puts the text on the clipboard once it has been selected and copied.  My problem is with selecting and copying. This functionality will be needed again I’m sure.  But I’ll describe this specific use case.

I have a display.newText object with about 40 lines of text.  They are algebraic functions:

2x+3

4(x^2-6x) +7

Students need to be able to select a function or a few functions and copy them onto the clipboard for use in Geogebra, Numbers, etc.  They are currently displayed in a widget.newScrollView object.  Select and copy within the scrollView window would be ideal, but I plan to pop out an overlay that allows students to copy and paste.  I haven’t been able to get native.textBox to work yet in an overlay even though it just sits on top of everything.

The pasteboard plugin will be used to push the selected text onto the IOS clipboard.  That part is working fine.

Sorry about that Scot, I wasn’t looking at the initial intent of your post. My bad.

More to the point, you might get some use out of the http://widgetstown.com site, which has a lot of modified native. code for Corona projects.

Thanks for the link.  widgetstown.com is just as strangely silent about the native.newTextBox widget as Corona Labs.  Wonder what the huge mystery is?  Seems pretty basic.

At this point I may just use a jack hammer to fasten a screw.  I could iterate over the text and create 40 display.newText objects and have a listener on each one that adds it to the clipboard.  Any other thoughts would be much appreciated.

If you’re looking to hightlight a portion of a display.newText object and copy only that portion you’re going to have a very hard time (and it’s likely impossible), because newText objects are rendered as images on the OpenGL canvas, so native-style hightlighting is not possible. (Somebody correct me if I’m wrong.)

I think since you don’t need the highlighted portion to be user-selectable (since they will need to copy the entire equation), your strategy of separating each line of text into a new newText object and adding a listener to copy the tapped object’s “.text” value is probably your best bet. And the “glass half full” way to look at it is that you don’t run the risk of the user accidentally missing part of the equation by under- or over-highlighting. This method gives you more control over what gets copied to the clipboard.

An interesting situation, for certain. I think this thread will be useful for other devs down the road. Good luck!

@schroederapps:

Thanks.  It is the direction I’m headed at the moment.  

BTW: I was able to approximate text selection using the touch event move phase by estimating the the location of the substring to copy based upon the location and width of the newText object.  It might be possible to create text selection that way.  I would have to usea Rect object to highlight.  Not worth doing for this  project.

Been writing code since the Timex Sinclair days.  Using the open GL canvas is no excuse for the lack of select and copy since all text is eventually rendered as a bitmap for display and the engine needs to know where to place the letter bitmaps.  To be clear, I recognize and support the design decisions Corona engineers have made.  I am just saying that they could, if it was a priority, develop select and copy.