Insert content into editor's body

I need to do one simple thing in the editor’s toolbar I have a button “Insert”, when clicked I would like to insert some text, sort of like keyword into editor’s body text at cursor position. How do I go about it.

Hi

add once:

dhtmlXEditor.prototype.insertText = function(text){ var range; if (this.edWin.getSelection) { var selection = this.edWin.getSelection(); range = selection.getRangeAt(selection.rangeCount-1); range.deleteContents(); } else if (this.edWin.document.selection) { range = this.edDoc.selection.createRange(); if (!range.duplicate) return; } range.insertNode(document.createTextNode(text)); }

then to insert text:

myEditor.insertText("text here");

Огромное спасибо, Андрей, в смую точку, то что и нужно было.

Andrei, for some reason, this one does not work in IE10, have not tried in IE11, but in IE10 gives me an error
SCRIPT5022: IndexSizeError

on line

range = selection.getRangeAt(selection.rangeCount - 1);

please help.

Hi

sorry for long response

try the following updates

dhtmlXEditor.prototype.insertText = function(text){ var range; this.edWin.focus(); if (this.edWin.getSelection) { var selection = this.edWin.getSelection(); range = selection.getRangeAt(Math.max(selection.rangeCount-1,0)); range.deleteContents(); range.insertNode(this.edWin.document.createTextNode(text)); } else if (this.edWin.document.selection) { range = this.edDoc.selection.createRange(); if (range.duplicate) range.text = text; } }

Andrei,
Thanks for getting back, I figured out work around.
That is what I wanted

“key words” hidden in the toolbar’s select button and you update does not work, it inserts text in the beginning of the editor’s body not in cursor position (in Chrome works fine).
So I had to put my keywords on top of the toolbar like this and it does work as intended

Thanks for your update.