Skip to main content
Participant
October 26, 2009
Answered

Creating a SpanElement from the current selection

  • October 26, 2009
  • 1 reply
  • 591 views

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 has been closed for replies.
Correct answer robin_briggs

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

1 reply

robin_briggsCorrect answer
Adobe Employee
October 26, 2009

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

Participant
October 27, 2009

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)."

Participant
October 27, 2009

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!