Thanks. I took your advice and thought I had everything working
nicely. Before I "update" the div my code recursively descends into
the div so that I can turn a "range component" (refNode + offset) into
an offset in a paragraph number. I tested this in firebug and it works
fine. After the div is rewritten (remember the paragraph and text stay
the same, but spans inside the paragraphs may come or go) I have code
that is similar to the "save" code discussed above except that it is
looking for a range component based on what was saved (paragraph
number and offset within the paragraph). This also seems to work fine.
But somehow, the insertion point (or selection) in the div does not
visually show up as being set, and I am following exactly what you
showed in the first code snippet in your reply as shown below. The
selection shows up as a collapsed selection at the beginning of the
div.

Did I miss something else?

On Jun 5, 8:24 pm, mkmanning <michaell...@gmail.com> wrote:
> For FF:
> window.getSelection().removeAllRanges();
> range = document.createRange()
> range.setStart(YOUR_ELEMENT, start_position);
> range.setEnd(YOUR_ELEMENT, end_position); //0
> window.getSelection().addRange(range);
>
> For IE the equivalent is something like:
> get the range with document.body.createTextRange()
> call moveToElementText, call setEndPoint, call moveStart, call
> moveEnd, then select().
>
> It's been a while since I've had to work with any of this (and
> fortunately I wasn't having to code for IE at the time).
>
> Getting your start position is part of the problem if the caret was in
> a bunch of nested elements. One thing that might help is to pass
> window.getSelection() to the Firebug console and then you can expand
> the object to see all of the available methods (which won't
> necessarily be the same in IE :( ).
>
> I'm afraid jQuery won't be of help here. A good source for information
> on the Range and Selection objects is 
> MDC:https://developer.mozilla.org/En/DOM:Range
>
> Unfortunately, cross-browser implementations of the Range object are
> inconsistent and the documentation minimal.
>
> HTH :)

Reply via email to