Hi,
I want to insert a line of text into the ckeditor when it's in 'source' mode. But I found that the 'inserthtml' function only works in 'wysiwyg' mode.
How can I implement the same function in 'source' mode without switching mode? Or is there any plugin that can handle this?
Thanks a lot!
I want to insert a line of text into the ckeditor when it's in 'source' mode. But I found that the 'inserthtml' function only works in 'wysiwyg' mode.
How can I implement the same function in 'source' mode without switching mode? Or is there any plugin that can handle this?
Thanks a lot!
I would like to know the same
I would like to know the same thing, please. Did you ever find a way? I don't care if the solution is for v3 or v4, I can use either. Thanks.
Anyone??
Anyone??
You can just use Ctrl+V.
You can just use Ctrl+V.
Sorry, we are not talking
Sorry, we are not talking about Copy/Paste, we are talking about using the insertHtml function (see original post). Any ideas? Why doesn't insertHTML work in Source mode?
Source/CodeMirror mode is not compatible
The Source and CodeMirror modes don't seem to be compatible with insertHtml, insertText and insertElement. Those functions are disabled from the plugin code.
When you enable the functions, there seem to be issues with the selected text, and cursor-position detection...
I now use a workaround, using the "textselection" plugin to get the cursor position:
More direct solution
I just had to figure this out, and while AvanOsch's solution above worked, I didn't like the way that the editor jumped back and forth when switching modes. Instead, I use this code which directly inserts the text at the proper location in source mode:
if (editor.mode == 'wysiwyg') {
editor.insertHtml( "text to insert" );
} else {
var caretPos = jQuery('textarea.cke_source')[0].selectionStart;
var textAreaTxt = jQuery('textarea.cke_source').val();
jQuery('textarea.cke_source').val(textAreaTxt.substring(0, caretPos) + "text to insert" + textAreaTxt.substring(caretPos) );
}
-Michael