Cursor position (javascript)

  •  12-16-2005, 9:51 AM

    Cursor position (javascript)

    Case: I want to perform a conditional pasteHTML in the editor pane. If the cursor at the moment is inside a <TABLE> tag, I'd want to move the cursor below the nearest </TABLE> before pasting.

    To perform this I'd preferably want to know the position of the cursor relative to the HTML text -even though the user currently is working in Normal mode.

    For those intrested, I have done a workaround but it is pretty dirty and slow:
    -I insert a token using the Editor.ExecCommand('PasteHTML',false,token);
    -Then i search for the token in the editor.GetDocument().body.innerHTML.
    -I then either replace the token with the text to be pasted, or remove the token depending on the surrounding tags.

    I don't know if it's because a bug or not, but when I alter the innerHTML, the Normal view suddenly looks like the Preview view (all table borders are lost, etc), so to mend this I perform a final dummy call to PasteHTML (empty content). 
     

    I don't like my solution  - I'd like to do with only one call to PasteHTML.

    Suggestions?

     

     

     
View Complete Thread