Have you figured this out yet?  I'm still trying to make it work.
You can do a getSelection() to get the Selection object in Mozilla.
Then use http://developer.mozilla.org/en/docs/DOM:Selection to modify
and read the cursor position.

The problem is, the Selection object methods are sort of difficult to
work with, and i can't get it to work for the life of me.

-Najib

On Jun 19, 5:27 pm, juodas <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have an interesting (at least for me :) problem and I guess I'm trying
> to solve it somehow backwards, so it would be better to consult more
> experienced ones javascripters.
>
> I have to replace some text sequences in editable area (it may be
> editable div or iframes body with design mode on) on a fly.
> I mean if user types 'foo' it has to become 'bar' if user types 'f oo'
> and latter deletes space it should become 'bar', if user pastes text
> "foo was fooing on fooland" it has to become "bar was baring on
> barland". That is - on every text change no matter where and how much
> sequences of 'foo' appear, all of them have to become 'bar'.
>
> Problem source:
> STEP 1: after catching modification event (for example onkeyup), I get
> innerHTML of editable element
> STEP 2: and execute appropriate regexp on result
> STEP 3: and latter assign it back to editable lelements.innerHTML
>
> PROBLEM RESULT: i loose cursor position in text.
>
> I have tried to use selection object, but either used it in wrong way
> either the reason is in reassigning innerHTML (that causes recreation of
> editable elements child nodes and old stored selection becomes invalid).
>
> Question is: how correctly to do above mentioned 'foo' -> 'bar' replace
> without loosing cursors position, or how to bring cursor back where it
> had been before replacement of content to new one?
>
> Big thanks to everyone who will give any idea - as I'm knocking my head
> to the table and trying not to bite the neck (cord) of my mouse (to make
> it bleeeead!! argh... at least for the last free days. :)
>
> P.S. sorry if cross posting to javascript, editor & dom is a bit too
> much - just all these three seemed quite related to my question from
> different points.



_______________________________________________
dev-tech-editor mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-editor

Reply via email to