[Mozile] OT: Range objects
James A. Overton
james at overton.ca
Thu Sep 21 10:34:43 EDT 2006
Hi Jeremy,
I think your crazy idea is a good one. Quite clever.
You answered your own question; walking the tree and counting text
node lengths is the only way to convert between the offset in the
text area and the offset in the rendered DOM fragment. Don't worry
about the speed. DOM read operations tend to be very fast. If you try
to do something with the Range object you'll have to worry about the
two completely different implementations Mozilla and IE provide.
I played with your code for a while and wrote a getElement() method
which seems to do what you asked. I made some other small changes
while I was hacking. You're free to use whatever you want.
There's still some tricky work to do. Once you have the element
where the changes occur, you're going to have to determine what text
should belong to that element. When the selection is not collapsed
(i.e. the start and end offsets are not the same) you'll have to
calculate the common ancestor element for the selection, and then get
its contents.
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mozdev.org/pipermail/mozile/attachments/20060921/5452124a/HighlightTest.html
-------------- next part --------------
More information about the Mozile
mailing list