Last active
June 27, 2021 09:15
-
-
Save vordan/954d90ae4c05ce5f2175 to your computer and use it in GitHub Desktop.
Skipping to an element within the CKEditor by ID and setting the cursor focus within that element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Skipping to an element within the CKEditor by ID and setting the cursor focus within that element. | |
// With the element in view, you'll attempt to insert the cursor at the beginning of the element using a Range. | |
// Firefox will actually insert the cursor for you but Chrome wont, so the Range step is necessary. | |
var element = evt.editor.document.getById('someHeading'); | |
var range; | |
if(element) { | |
element.scrollIntoView(); | |
// Thank you S/O | |
// http://stackoverflow.com/questions/16835365/set-cursor-to-specific-position-in-ckeditor | |
range = editor.createRange(); | |
range.setStart(element, 0); | |
range.setEnd(element, 0); | |
editor.getSelection().selectRanges([range]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment