Skip to main content
Participant
Oct 26, 2009 4:20 PM UTC
Answered

Creating a SpanElement from the current selection

Hi all,

I'm trying to create a SpanElement from the current selection. I need to assign an ID to the selected text so I can refer back to it later. I've looked in my TextAreas interactionManager and flowComposer and I can't figure out a way to do it. Any ideas?

Cheers,

James

This topic is closed to new replies. Start a new post to keep the conversation going.
robin_briggsCorrect answer
Adobe Employee
Oct 26, 2009 7:57 PM UTC

The easiest way to apply the ID would be to use the ApplyElementIDOperation, which takes a span and a relative start/relative end. If you want the whole span to get the ID, pass 0, spanElement.textLength. But you can get a subset of the span to get the ID by passing other values. This will break the original span up into smaller spans. After the operation, there will be a span element that has just the range indicated, with the ID applied.

- robin

3 replies

robin_briggsCorrect answer
Adobe Employee
Oct 26, 2009 7:57 PM UTC

The easiest way to apply the ID would be to use the ApplyElementIDOperation, which takes a span and a relative start/relative end. If you want the whole span to get the ID, pass 0, spanElement.textLength. But you can get a subset of the span to get the ID by passing other values. This will break the original span up into smaller spans. After the operation, there will be a span element that has just the range indicated, with the ID applied.

- robin

Translate
Participant
Oct 27, 2009 10:44 AM UTC

Thanks for the answer, that seems like a good way of doing it.

But how do I get the Operation to execute? Do I need to extend the EditManager? From the language ref:

"Most applications do not need to create or manage operations directly (unless implementing a custom edit manager)."

Translate
Participant
Oct 27, 2009 10:53 AM UTC

I figured it out. I needed to add my text flow to the operation and then call doOperation() on the object itself.

That works, thanks again for your help!

Translate