Skip to main content
Participating Frequently
Nov 22, 2009 9:38 AM UTC
Question

Line Breaks using span.splitAt

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 is closed to new replies. Start a new post to keep the conversation going.

4 replies

Inspiring
Nov 23, 2009 4:01 AM UTC

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

Translate
Participating Frequently
Nov 23, 2009 5:25 AM UTC

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.

Translate
Adobe Employee
Nov 23, 2009 5:56 AM UTC

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

Translate