3

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...

Community
  • 1
  • 1
Yael
  • 83
  • 2
  • 5

2 Answers2

2

This will work for Ckeditor5:

editor.model.change( writer => {writer.setSelection( editor.model.document.getRoot(), 'end' );} );
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
1

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

Community
  • 1
  • 1
wfy
  • 46
  • 5
  • Sorry, You have already post this link, if it doesn't work, please ignore it. – wfy Sep 23 '14 at 06:42
  • Thanks anyway, I've tried the bookmarks as well and it doesn't seem to work - any ideas? – Yael Sep 23 '14 at 08:44
  • I think it's because you changed the text before bookmark, so the bookmark address's element changed. – wfy Sep 23 '14 at 08:51
  • Or you can try this method editor.getSelection().selectBookmarks([bookmark]) – wfy Sep 23 '14 at 08:54
  • Thanks again - the problem with setting bookmarks is that I change the dom, elements are added so the ranges and selection no longer match - so I can't use the bookmarks of before my change – Yael Sep 29 '14 at 13:14