0 Replies Latest reply on May 12, 2011 6:45 AM by pvjedder

    setFormatOfRange loses formatting when textArea.text is changed

    pvjedder

      I'm building a text editor within a larger web application where a user can edit a TextArea and format the text any way they want, on a character by character basis, if that user desired.  It's for that reason that I need to use setFormatOfRange.  However I'm running into a stumbling block with that function.  Additionally, the user can double click the box to edit the actual text in a possibly more readable popup interface.  For example, this would be useful if a user has a small text box with even smaller text that can be barely readable on the screen (for example a disclaimer).  Bringing up this text box will allow the reader to edit the text in a readable manner without changing the formatting of the box.  At least, in theory.  After I reset the original box's text with the new text, it reverts back to the original formatting that was not set by setFormatOfRange.  The code that I'm using is complex, but I have an example that shows exactly what I'm talking about, and a decent representation of how I will be using setFormatOfRange.

       

       

      public function formatTest():void

      {

       

           var newStyleObj:TextLayoutFormat = new TextLayoutFormat();

           newStyleObj.fontSize = 20;

           testText.setFormatOfRange(newStyleObj,0,testText.text.length);

      }

      public function formatTest2():void
      {
           testText.text = "hello!!";
      }
      <s:TextArea id="testText" visible="true" x="142" y="31" width="197" height="69" text="this is a test"/>
      <s:Button x="606" y="65" label="Button 1" click="formatTest()"/>
      <s:Button x="686" y="65" label="Button 2" click="formatTest2()"/>

       

      The TextArea is prepopulated with "this is a test", and when Button 1 is clicked, it will change the size to 20.  When Button 2 is clicked, it will change the text to "hello!!", but it also reverts back to the default, pre-setFormatOfRange size.

       

      Many people may suggest that I don't use setFormatOfRange, but instead use setStyle on the whole textArea.  This won't work, however, since a user can essentially change the formatting on each character in the textArea.  I'd have to loop through the entire textArea on a character by character basis and use getFormatOfRange and setFormatOfRange in order to preserve the formatting.
      Is there any solution to this? Thanks!