4 Replies Latest reply on Mar 31, 2010 12:33 PM by dsidharta

    Spark TextArea's insertText() Not Recognizing Paragraphs

    dsidharta

      Dear all:

       

      TextArea's insertText() doesn't seem to create the appropriate paragraphs for a text that has line breaks ("\n", "\r\n", "\r"). Here's a simple example, inspired by http://blog.flexexamples.com/2009/07/24/creating-a-simple-text-editor-using-the-spark-text area-control-in-flex-4/:

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application name="Spark_TextArea_setFormatOfRange_test"
                     xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/halo">
          <fx:Script>
              <![CDATA[

                  // Imports here ....
                 
                  private function onExport(event : MouseEvent) : void {
                      var xmlExport : XML = TextFlowUtil.export(editor.textFlow);
                      var result : String = xmlExport.toString();
                      log.appendText(result);
                  }
                 
                  private function onInsert(event : MouseEvent) : void {
                      var text : String = "paragraph 1\n";
                      text += "paragraph 2\r\n";
                      text += "paragraph 3\r";
                      editor.insertText(text);
                  }
                 
              ]]>
          </fx:Script>
         
          <s:Panel title="SimpleTextEditor"
                   width="100%" height = "100%"
                   horizontalCenter="0" verticalCenter="0">
              <s:layout>
                  <s:VerticalLayout gap="0" />
              </s:layout>
              <s:TextArea id="editor"
                          focusEnabled="false"
                          width="100%" height="100%"
                          minHeight="200" />       
              <s:TextArea id = "log" editable="false" width = "100%" height = "100%" />
              <s:controlBarContent>
                  <s:HGroup id = "appControlBarGroup" width = "100%">
                      <s:Button id = "exportToTLF" label = "Export to TLF" click = "onExport(event)" />
                      <s:Button id = "insertText" label = "Insert Text" click = "onInsert(event)" />
                  </s:HGroup>
              </s:controlBarContent>
          </s:Panel>
      </s:Application>

       

      You will notice that "paragraph 1", "paragraph 2", and "paragraph 3" are all regarded as the same paragraph. You may inspect the exported text layout format. Am I missing something or making a mistake somewhere? Thanks in advance for the pointer!