Skip to main content
Known Participant
June 17, 2009
Question

Overwrite Text Functionality

  • June 17, 2009
  • 1 reply
  • 1486 views

Hi,

I would like to overwrite text in a textFlow with new text, keeping the currently selected format.

            IEditManager(_textFlow.interactionManager).setSelection(0,_textFlow.textLength);
            IEditManager(_textFlow.interactionManager).overwriteText(txt);

Sadly, however, the text gets inserted before the existing text, the "old" text is highlighted. Is there a different way? How can I replace the complete text of a textFlow?

I am using the original November built.

For any hint I'd be extremely greatful.

This topic has been closed for replies.

1 reply

brian_thomas2
Adobe Employee
Adobe Employee
June 19, 2009

If EditManager.overwriteText() is not functioning correctly, this sounds like a bug. Have you tried this on our latest weekly builds?

http://labs.adobe.com/downloads/textlayout.html

A_Shiyaz
Known Participant
August 17, 2010

May be an old post, but useful to someone:

To overwrite use this:

var selState = new SelectionState(textFlow, 0, textFlow.interactionManager.absoluteEnd);
EditManager(textFlow.interactionManager).deleteText(selState);
EditManager(textFlow.interactionManager).overwriteText("abc", selState);

If you just want to append content, just use:


EditManager(textFlow.interactionManager).overwriteText("abc");

~ Shiyaz

[Edit]:

For some reason, the absoluteEnd gives -1 at times. However, we need the length of the text. Hence, use this:

var str = TextConverter.export(textFlow, TextConverter.PLAIN_TEXT_FORMAT, ConversionType.STRING_TYPE) as String;
var selState = new SelectionState(textFlow, 0, str.length);
EditManager(textFlow.interactionManager).deleteText(selState);
EditManager(textFlow.interactionManager).overwriteText("abc", selState);

~ Shiyaz

Message was edited by: A.Shiyaz

August 27, 2010

I don't think you go with that hack : delete and insert text, because in the future they might change something to one of the operation and it might break your code.

In their documentation for overwriteText, they give the following example

var textFlow:TextFlow = TextConverter.importToFlow( "How zzz brown cow.", TextConverter.PLAIN_TEXT_FORMAT );
textFlow.flowComposer = new StandardFlowComposer();
textFlow.flowComposer.addController( new ContainerController( this ));
var editManager:EditManager = new EditManager( new UndoManager() );
textFlow.interactionManager = editManager;
textFlow.flowComposer.updateAllControllers();

editManager.setSelection( 4, 6 );
editManager.overwriteText( "now" ); //Displays: How now brown cow.


I use 4.1 SDK and I there's no setSelection method. Instead I used selectRange, which take the same parameters as setSelection and the results are the way I expected.