views:

385

answers:

2

If you have two text areas with different styles (fontFamily, weight, color etc) and you copy text from one to the other it also copies the style from the originating text area. Is there any slick way to prevent that?

Here is a sample of code that will illustrate the problem. Type some text in the top box and some text in the bottom, then copy some characters from the top box to the bottom. I'm not using htmltext.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
  <mx:VBox width="100%" height="100%">
    <mx:TextArea id="source" width="100%" fontWeight="bold" fontSize="20" height="50" />
    <mx:TextArea id="dest" width="100%" height="50" /> 
  </mx:VBox>
</mx:Application>
A: 

Can you show a code example?

My first guess is that you are setting the htmlText property of the first text area, and your colours and styles are via HTML. Are you copying the html tags with your copy? You might need to override the text or htmlText setter and strip out the tags (or change them).

I'm not even sure a copy/paste of a textarea will copy the HTML inside. Seems plausible though.

Glenn
Nope. I'm setting the text property, not using htmlText at all. If I were using htmlText then I could maybe see the problem occuring.
Shizam
Wow! You're right. Tested the code. That's insane. You still might be able to get around it using an override to the "text" or "htmlText" setters. Seems like it is taking some HTML formatting with it.
Glenn
Nope. Had a little play around. Internally, the "textField" element contains htmlText, not the textArea itself. You have to play with greg's solution. That's pretty much the closest I can see.
Glenn
Hah, good to know I'm not just crazy, thanks for confirming :)
Shizam
+2  A: 

Here's a horribly dirty hack that gets it done:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    >

    <mx:Script>
     <![CDATA[

      public function reformat():void
      {
       var hold:String = two.text
       two.text = ""
       two.htmlText = hold
      }


     ]]>
    </mx:Script>

    <mx:VBox width="100%" height="100%" >

     <mx:Button click="bonk()" />

     <mx:TextArea fontWeight="bold" id="one" width="100%" height="100%" />

     <mx:TextArea fontWeight="normal" id="two" width="100%" height="100%" change="reformat()" />

    </mx:VBox>


</mx:Application>
greg
This is very close to the solution. The only downside here is two.text is now empty and you have to use htmlText, any way to keep two.text populated with the text as well?
Shizam