Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2006-08-06 05:40:30

sajed
New member
Registered: 2006-08-06
Posts: 1

Cursor position after insertHTML

Hi,

After insertHTML() is called, the cursor is positioned to the left of the inserted html, instead of being on the right. This causes problems because after consecutive calls to insertHTML(), the order of inserted html is reversed.

Does anyone know a fix/workaround for this?

thanks,

-Sajed

Offline

#2 2006-08-11 12:06:00

e-vision
New member
Registered: 2006-08-11
Posts: 1

Re: Cursor position after insertHTML

Hi,

I was solving similar problem. I needed to insert      on <TAB> key press to indent source code written in xinha.

The code, that inserts 4 spaces BEFORE cursor is here:


    // cannot use - moves cursor before inserted text
        //editor.insertHTML("    ");
       
        var sel = this._getSelection();
        var range = this._createRange(sel);
        var node = range.startContainer;
        var pos = range.startOffset;

        tag = editor._doc.createTextNode("    ");
    node.parentNode.insertBefore(tag, node);

It places 4 spaces only before text, not inside (I don't need that feature). To solve this problem you need to split text node into 2 separate text nodes and insert another node between them. The cursor should stand after last inserted node I hope. Index of cursor in text node is in the "pos" variable

Hope this helps you

Last edited by e-vision (2006-08-11 13:24:47)

Offline

Board footer

Powered by FluxBB