1

Topic: cursor position

I have developed a couple of my own plugins and would also like to slightly modify the existing mceLink funciton.  The issue is that after you insert a link and then continue typing then everything becomes part of the link. It happens because my cursor is still INSIDE the <a> tag. how do I move my cursor one position ahead so that its outside the link tag?? any suggestions?

2

Re: cursor position

I have the same problem, did you find any solution?

3

Re: cursor position

Well,

I used the function from http://tinymce.moxiecode.com/punbb/view … hp?id=1406 and it works fine smile

// This is the function that moves the cursor to the end of content
function moveCursorToEnd(editor_id) {
    inst = tinyMCE.getInstanceById(editor_id);
    tinyMCE.execInstanceCommand(editor_id,"selectall", false, null);
    if (tinyMCE.isMSIE) {
        rng = inst.getRng();
        rng.collapse(false);
        rng.select();
    }
    else {
        sel = inst.getSel();
        sel.collapseToEnd();
    }
}

4

Re: cursor position

I just came up with a clever little stupid hack. Not sure if it works in IE or outside of wordpress but who cares. Or I don't or something

tinyMCE.execCommand( 'mceInsertContent', false, mytext+' ');
tinyMCE.execCommand( 'mceInsertContent', false, ' ');

Replace mytext with your text to be inserted.
There has to be on nbsp(thats what the   means) stuck to the end of the inserted text, and then you have to make a seperate tinyMCE.execCommand to insert another  
You can replace the first   with   (space) but the second one seems to need the  

If anyone is wondering what the   and   are, they are html codes

ps... Is there only one guy who makes this program? Because that seems a little crazy considering the possibly 100 million or more users when you think count wordpress and everyone else.

Last edited by mikeL (2008-03-25 09:56:30)

5

Re: cursor position

liomo wrote:

// This is the function that moves the cursor to the end of content
function moveCursorToEnd(editor_id) {
    inst = tinyMCE.getInstanceById(editor_id);
    tinyMCE.execInstanceCommand(editor_id,"selectall", false, null);
    if (tinyMCE.isMSIE) {
        rng = inst.getRng();
        rng.collapse(false);
        rng.select();
    }
    else {
        sel = inst.getSel();
        sel.collapseToEnd();
    }
}


Maybe it depended on what version of TinyMCE I had, but I had an exception so I changed a segment to: sel=inst.selection.getSel();