You are not logged in.
#1 2010-02-08 20:58:02
- laurelwilliams
- Member
- Registered: 2010-02-03
- Posts: 5
how to move caret after insertion
Hi all,
I am inserting text into my editor content using a very simple plugin. Below is the init object in editor_plugin_src.js
If text is highlighted when the user clicks my custom button, then [?]text[/?] is inserted into the content. If no text is highlighted, it just inserts [?][/?]. In that second case, I would like to move the caret to be placed in between the two [?] [/?] tags. I have searched through the API, but I can't find anything that will allow me to do this. Any ideas?
Thanks in advance.
Laurel
Code:
init : function(ed, url) {
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceInsert_tag');
ed.addCommand('mceInsert_tag', function() {
var selected = ed.selection;
selected.setContent('[?]' + selected.getContent() + '[/?]');
});
// Register example button
ed.addButton('insert_tag', {
title : 'insert_tag.desc',
cmd : 'mceInsert_tag',
image : url + '/img/insert_tag.png'
});
},Offline
#2 2010-03-08 23:01:53
- stevenmc
- Member
- Registered: 2009-02-12
- Posts: 29
Re: how to move caret after insertion
Hi Laurel, this link should help you to get on your way...
http://wiki.moxiecode.com/index.php/Tin … etBookmark
Last edited by stevenmc (2010-03-08 23:15:17)
Offline
#3 2010-03-10 19:23:15
- laurelwilliams
- Member
- Registered: 2010-02-03
- Posts: 5
Re: how to move caret after insertion
Hi,
The bookmarking technique is a good idea, but didn't work in the case I was using, since I couldn't find a way to bookmark a cursor location that doesn't exist before executing the plugin code. My plugin is a button which inserts [?][/?] into the editor text at the insertion point. This tag is processed later on the fly when the user content is submitted. I wanted to place the cursor between the two tags so that the user could type some text there immediately after inserting the tags.
Here is what I ended up doing:
Code:
ed.selection.setContent('[?]'<span id="remove_me"></span>[/?]'); //insert the tags with a span in between
ed.selection.select(ed.dom.select('span#remove_me')[0]); //select the span
ed.dom.remove(ed.dom.select('span#remove_me')[0]); //remove the spanUpon removal of the remove_me span, the cursor remains between the two ? tags.
Worked for me, but if you have a better suggestion, let me know!
Offline
© 2003-2010