Skip to main content
December 22, 2009
Answered

Split and Merge Paragraphs

  • December 22, 2009
  • 1 reply
  • 1396 views

When I split and merge a paragraph a line break is inserted.  Does anyone know a way around this. (Simply deleting the last character seems inelegant and, more importantly, prone to failure).  Here's the code:

var textFlow:TextFlow = TextConverter.importToFlow(
                    "Hello World",
                    TextConverter.PLAIN_TEXT_FORMAT);
textFlow.interactionManager = new EditManager();
var textFlow2:TextFlow = textFlow.splitAtPosition(5) as TextFlow;
textFlow2.interactionManager = new EditManager();
textFlow.mxmlChildren = textFlow.mxmlChildren.concat(textFlow2.mxmlChildren);
trace(textFlow.getText()); // returns "Hello\n World"

- Daniel Freiman

This topic has been closed for replies.
Correct answer rdermer

If you are asking how to split and merge a paragraph this works.

            var textFlow:TextFlow = TextConverter.importToFlow("Hello World",TextConverter.PLAIN_TEXT_FORMAT);
           
            // find the paragraph
            var para:ParagraphElement = textFlow.findLeaf(5).getParagraph();    // same as textFlow.getChildAt(0)
            // split paragraph at position five
            var newPara:ParagraphElement = para.splitAtPosition(5) as ParagraphElement;
            trace(textFlow.getText());
           
            // now the merge
           
            // remove newPara its being discarded
            newPara.parent.removeChild(newPara);
            // move the children
            while(newPara.numChildren)
                para.addChild(newPara.getChildAt(0));
           
            trace(textFlow.getText());

This is using pure model level calls.  In your original code you added an EditManager- it can be done that way too.  TLF is layered - the EditManager manipulates the model with model level calls.  It provides APIs connected to events that create operations do to that.

Hope that helps,

Richard

1 reply

Adobe Employee
December 22, 2009

There's no merge here.  When you assign mxmlChildren at the end the result is two paragraphs.  getText is inserting a paragraph separator which defaults to a newline.

BTW using mxmlChildren isn't recommended - that method exists for the support of the mxml compiler. Better to use replaceChildren.

Hope that helps,

Richard

December 22, 2009

I understand that this is the problem.  I'm trying to figure out how to solve it using a comprable method.  Cut and Paste through EditManager doesn't seem to help.  Is there any other method out there?

Adobe Employee
December 22, 2009

We recently added a getText() function to FlowElement, which has a parameter for the paragraphSeparator -- in this case, it's a separator, not a terminator, so you will get one between elements but not at the end.

- robin