Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ckeditor - Cursor position always gets to the start after setData

I'm using angular, and set the data of ckeditor with ngModel - when we render we set the data

editor.setData(ngModel.$viewValue);

We try to keep the cursor selection with ranges and bookmarks

but it always get to the start even if there are no DOM changes

I've tried many solutions such as

CKEditor: set cursor/caret positon

Set cursor to specific position in CKEditor

Couldn't make it work... :(

Can anyone help please...

like image 320
Yael Avatar asked Sep 05 '25 15:09

Yael


2 Answers

This will work for Ckeditor5:

editor.model.change( writer => {writer.setSelection( editor.model.document.getRoot(), 'end' );} );
like image 120
Ajay Shukla Avatar answered Sep 09 '25 22:09

Ajay Shukla


Try this:

var range = editor.createRange();
range.moveToElementEditablePosition( editor.editable(), true );
editor.getSelection().selectRanges( [ range ] );

Got it from this link Set cursor to specific position in CKEditor

like image 34
wfy Avatar answered Sep 09 '25 21:09

wfy