How to blur caret in CKEditor?

2019-08-17 03:55发布

I am using CKEditor in inline mode. I am focusing and immediately blurring (for testing) using the following:

var editor = CKEDITOR.dom.element.get( e.currentTarget.getDOMNode());

editor.getEditor().focus();
editor.getEditor().focusManager.blur(true);

I want to blur the editor and focusManger.blur(true) results in the toolbar being hidden. However, the caret is still focused. For some reason, I cannot find a way to defocus and remove the caret. I have tried calling focus() on another DOM element, but the caret still persists.

How can I call blur() to remove the caret as well?

2条回答
Lonely孤独者°
2楼-- · 2019-08-17 04:16

The only way I was able to solve this is to blur the contenteditable div:

CKEDITOR.currentInstance.element.$; //Grab the DOM node which is the contenteditable
CKEDITOR.currentInstance.element.$.blur(); //Blur it
CKEDITOR.currentInstance.focusManager.blur(true); //CKEditor's blur hides the toolbar
查看更多
太酷不给撩
3楼-- · 2019-08-17 04:24

Isn't this enough?

editor.editable().$.blur();

It works for me.

查看更多
登录 后发表回答