0

I am trying to create a custom tag and have the cursor set between opening tag and closing tag. Something like this: [youtube]{cursor_here}[/youtube].

I have something like this so far:

            var selectedText = editor.getSelection().getNative(); 
            if(selectedText === null ){
                //ToDo: add youtube tag with cursor positioned in the middle
            } else {
                var openTag = '[youtube]';
                var closeTag = '[/youtube]<br />';
                editor.insertHtml(openTag + selectedText + closeTag);
            }

I also tried the approach with editor.insertElement but I couldn't get it solved out with custom tags.

The idea behind this is to have the user ready to paste a link (like a youtube link) after he pressed a custom button that inserts the tag. Without external dialogs.

1 Answer 1

0

Found a solution using this post

Looks like this:

            var sel = editor.getSelection();
            var ranges = sel.getRanges();
            var inserted = ranges[0].startContainer.getNext();
            ranges[0].setStart(inserted, 9);
            ranges[0].setEnd(inserted, 9);
            sel.selectRanges([ranges[0]]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.