Skip to main content
Participating Frequently
November 22, 2009
Question

Line Breaks using span.splitAt

  • November 22, 2009
  • 1 reply
  • 582 views

I am trying to implement a function that inserts BreakElements at a given position when the user presses the Shift+Enter keys. In order to prevent the default behavior of the EditManager (splitParagraph), i tweaked the keyDownHandler to differenciate between Enter and Shift-Enter).

It works fine, but i would like to define an operation for inserting breaks, so the user can undo it, just like undoing any TextOperation, I started making my own class that extends FlowTextOperation and filled in this code in the doOperation method

public override function doOperation():Boolean

{

var span:SpanElement = textFlow.findLeaf(textFlow.interactionManager.activePosition);

var p:ParagrahElement = span.getParagraph();

span.splitAtPosition((textFlow.interactionManager.activePosition - span.getAbsoluteStart());

var br:BreakElement = new BreakElement();

var index:int = p.getChildIndex(span);

p.addChildAt(index+1,br);

return true;

}

Any ideas on how to implement the undo method?

Is it impossible because inserting a FlowElement is not managed by the EditManager and so the stack of operations is flushed?

thanks!

This topic has been closed for replies.

1 reply

Adobe Employee
November 23, 2009

For performance reasons TLF doesn't use BreakElements (and TabElements) except during import.  After that they normalized to \n in a SpanElement which gets merged with its neighbors.  That's fewer TLF objects and fewer FTE objects.

For your operation I'd suggesting using InsertTextOperation with \n.

Hope that helps,

Richard

Participating Frequently
November 23, 2009

Thank you for your reply!

I am interested in seing the "<br />" tag when i export the textFlow, but i guess i can do the conversion ('\n' => '<br />') right before sending the text to the server side.

Adobe Employee
November 23, 2009

I think if you use the Unicode character '\u2028', it will do the same as what <br/> does, and will automatically get converted to a <br/> on export.

- robin