Skip to main content
Participating Frequently
October 19, 2010
Question

Copy/Paste within TextFlow

  • October 19, 2010
  • 1 reply
  • 667 views

I'm using a TextFlow with added controllers by using textFlow.flowComposer.addController(controller).
When I paste text from other programs (like firefox or word) the text gets wrong formating (expecting the same formating as the text surrounding it).

One solution could be to catch the paste-event and do something with it, but it doesn't show up on either the TextFlow-object or the containers inside of it.

The code I'm using for the textflow is (using FlashDevelop):

            textFlow.addEventListener(Event.PASTE, function (event:Event):void {
                var clip:String = Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT) as String;
                FlashConnect.trace(clip, TraceLevel.DEBUG);
            });

The code I'm using for each container is (using FlashDevelop):

            container.addEventListener(Event.PASTE, function (event:Event):void {
                var clip:String = Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT) as String;
                FlashConnect.trace(clip, TraceLevel.DEBUG);
            });

This topic has been closed for replies.

1 reply

Adobe Employee
October 19, 2010

TLF does has an event handler it is registering for Event.PASTE, and one way to tie into that would be to override the EditManager.editHandler function and then to substitute your own code. To do that, you would create your own EditManager class, derived from EditManager, and put your new code in the editHandler function. When you set up the TextFlow, set its interactionManager to an instance of your new EditManager class. Now your editHandler will be called when the user does a paste.

What should your code do when it's called? Well, whatever you want, of course. One thing I'd suggest is to save off the leaf-level format and the paragraph-level format at the start of the paste position, and then apply these as format changes after the paste is completed.

We do have a bug logged on this for TLF 2.0, and I am looking into fixing it right now. Coincidence! I expect that there will be a fix for this in our SourceForge depot in the next week, but to get that you'd have to pick up our pre-release. To avoid that, you can use the workaround I described above.

Thanks,

- robin