Skip to main content
Participant
August 13, 2009
Question

Equivalent of applyLeafFormat() for SelectionManager?

  • August 13, 2009
  • 1 reply
  • 964 views

Hi-

I'm trying to add the ability for users to select a chunk of text in a textflow, and then we'll highlight it (i.e., change the backgroundColor and backgroundAlpha). I can make this working following the basic premise from the SimpleEditor sample:

var cf:TextLayoutFormat = new TextLayoutFormat();

cf.backgroundColor = 0xff0000;

cf.backgroundAlpha = 1;

IEditManager(_textFlow.interactionManager).applyLeafFormat(cf);

_textFlow.interactionManager.setFocus();

But that example works with an EditManager as the interactionManager. We do not want users to be able to edit the textflow, though.

So, there are two pathways, and I don't know how to do either one:

1. Could I have an EditManager, but dis-allow all interactions that would lead to the content of the text changing?

2. Can I get the selected range from a SelectionManager and apply text formatting to that range?

(I'm using rev 460 right now, if that matters.)

Thanks!

-Matt

This topic has been closed for replies.

1 reply

Adobe Employee
August 14, 2009

A couple of ideas.

1) Just swap the SelectionManager for an EditManager for the duration of the operation

2) Create your own override of EditManager and filter the events

3) Just create an ApplyFormatOperation and .call doOperation

4) Call ParaEdit.applyTextStyleChange directly.

Too many options I suppose - depends a bit on if you want undo.  Easiest is to go for 4.  It's not documented but isn't likely to change for 1.0.

The function signature is:

public static function applyTextStyleChange(flowRoot:TextFlow,begChange:int,endChange:int,format:ITextLayoutFormat):

void

flowRoot is the TextFlow, begChange is SelectionManager.absoluteStart, endChange is SelectionManager.absoluteEnd and format is a new TextLayoutFormat with just the background color values filled in.

Hope that helps,

Richard

theBargeAuthor
Participant
August 17, 2009

Those were great ideas! What I ended up doing was, since I knew the absoluteStart and absoluteEnd of the selection, walking through all of the leaf elements of the textflow and seeing what the selection caontained (splitting leafs when necessary to make new leafs) that I could then set a backgroundColor/backgroundAlpha on. It might be slower than your suggestions, but we're dealing with a small enough quantity of text that I think it'll be OK. Thanks for your ideas though!