Yes, I am using jQuery.

I found that it's pretty trivial to set the position for a single text
node.

The problem I run into is when there are multiple elements within the
div. For example:

<div editableContent="true>
    Here is <span class="GrammarError" message="Repeated Word">some
some</span> text.
</div>

It is easy to set the position to "4" in this case, because the first
text node will report the offset as "4".

The problem is if the user has the cursor within "some some". If they
had it between the "so" and "me", it would report an offset of 1 (or
2) - not 10 (or 11) like you would expect.

Basically, the cursor position resets to 0 for every kind of node
inside of the div.

I will try out that jquery code just to make sure. Maybe it'll work.
It's looks too simple though as I have built my own abstractions on
the around selection/range to take care of cross browser and find
myself trying the same kind of thing as suggested on that page :(

On Apr 7, 1:09 pm, Steel City Phantom <[email protected]> wrote:
> are you using jquery?  if so,
>
> http://stackoverflow.com/questions/499126/jquery-set-cursor-position-...
>
> <http://stackoverflow.com/questions/499126/jquery-set-cursor-position-...>i
> have to put some more thought on which event you would have to use to
> trigger it.
>
> in worst case, pull down the jquery code and find the method and see how
> they do it.  i switched to jquery a long time ago, makes everything much
> easier and you have a fairly reasonable guarantee that it will work cross
> browser.
>
>
>
> On Wed, Apr 7, 2010 at 9:49 AM, egervari <[email protected]> wrote:
> > I'm a long time listener. I'm actually the guy that sent him that
> > scala question with the name "Huge G. Rection" if you remember that ;)
> > That crazy guy from Canada!
>
> > Anyway... I'm having a problem with JavaScript and I thought since
> > this community is way smarter than average communities, I might be
> > able to find an answer here.
>
> > If I'm using editable content divs... is there a way to easily get/set
> > the cursor? Gmail makes this look easy, but it's actually not an easy
> > problem.
>
> > My div contains text and other html elements - notably several
> > <span>'s. These span's indicate grammar errors and the like. So when
> > the person types text into the editor, we have to drop some text nodes
> > from the div and replace them with the spans. These spans add those
> > nice red squiggles and also provide tooltips indicating how to fix the
> > grammar error.
>
> > Every time I change the contents of the editable div, firefox will
> > reset the cursor to the beginning of the content box (annoying!) and
> > IE will reset it to the end (not as bad, but still a problem if they
> > edit text in the middle).
>
> > Now, I know there's selection objects and range objects. The problem
> > with these is that if the anchor/start nodes they were pointing to are
> > deleted, the browser auto-magically points them to other elements of
> > the DOM. In Firefox, it's the parent div container. In IE, it's
> > something else.
>
> > Is there another way I can save/restore selection (i.e. cursor) state?
> > Or do I have to wrap every word and space character with a <span> tag
> > just to avoid deletions?
>
> > I've spent about 6 hours on this problem, which is actually more than
> > it took to build the entire ajax grammar checker. I'm a little
> > frustrated and looking for help.
>
> > I realize this is a JavaScript question, but it's for a Java
> > application :)
>
> > Thanks!
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "The Java Posse" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<javaposse%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/javaposse?hl=en.
>
> --
> You want it fast, cheap, or right.  Pick two!!

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to