0

I am trying to get the char position/ char count of where the selected text occurs in the doc.

for example i am doing

var selectedText = rangy.getSelection().getRangeAt(0);

I need to figure how where in the document this is by char count and save the stop start character positions. The selected text may occur more than once so trying to do a indexof will not work. I was hoping i could get that info from rangy, since i already have the selected text

Thanks for any help

randy

randy
  • 1,685
  • 3
  • 34
  • 74

1 Answers1

0

You can use the SerializerModule from rangy to serialize your selection:

rangy.serializeRange(rangy.getSelection().getRangeAt(0)); 

You can also decide if you want a checksum and it's also good to specify the root node:

rangy.serializeRange(rangy.getSelection().getRangeAt(0), false, document.getElementById("myRootNode")); 

Another way is to use HighlighterModule and highlight your text. It also provides the ability to serialize the highlight.

Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
  • thanks for the help. Not sure this help. I am looking at it. I need actual char start and char stop position in the doc string – randy Jul 17 '13 at 18:03
  • Why? rangy will do the annotation and serialization for you. – Vivin Paliath Jul 17 '13 at 19:18
  • because that is my requirement – randy Jul 17 '13 at 19:32
  • @randy So you require the start and stop character position if the entire DOM was interpreted as HTML? – Vivin Paliath Jul 17 '13 at 20:35
  • i have a large amount of non-html ascii text that has been placed inside a div. The user then right clicks the ascii text and i send the selected text and the char positions to another webservice – randy Jul 18 '13 at 11:55