Paste CodeMirror elements in HTML JQUERY Editor

I am using CodeMirror (see here β†’) codemirror . In particular, I am using the HTML Preview Editor module.

I tested it in the fiddle: -------> http://jsfiddle.net/Vu33n/6/

I got an editor to work, but I'm trying to make the user select an HTML tag from the drop-down menu - this code will be inserted into the editor, where the CURSOR POSITION is.

I can get the code to paste into the editor, but it erases everything in the editor before pasting it. I cannot get him to paste the code where the cursor is and leave everything else alone.

The syntax of CodeMirror that I use is:

editor.setValue($(this).val()); 

If you're interested, the CodeMirror user guide is here . This is where I found 'setValue'

+4
source share
2 answers

I apologize. I finally found the answer here - > replaceSelection

So, the code should be read:

 editor.replaceSelection($(this).val()); 

Sorry for the message - but maybe this will help someone else in the future.

+3
source

Proposed Change:

 editor.replaceSelection($(this).val()); 

works fine in JSFiddle: http://jsfiddle.net/Vu33n/181/ Go ahead and accept your own answer.

0
source

Source: https://habr.com/ru/post/1491532/


All Articles