admin管理员组文章数量:1315792
I'd like to listen to the focus event in CKEditor 5.
I thought something like this would work but the callback is never called:
document.querySelector("#editable");
ClassicEditor.create(el).then(editor => {
editor.on('focus', () => {
console.log("Focused");
});
});
The editor is successfully created but the callback is not called.
Any ideas?
I'd like to listen to the focus event in CKEditor 5.
I thought something like this would work but the callback is never called:
document.querySelector("#editable");
ClassicEditor.create(el).then(editor => {
editor.on('focus', () => {
console.log("Focused");
});
});
The editor is successfully created but the callback is not called.
Any ideas?
Share Improve this question asked Apr 5, 2018 at 3:22 Michael BatesMichael Bates 1,9342 gold badges30 silver badges43 bronze badges1 Answer
Reset to default 10The editor es with a FocusTracker
(and the observable #isFocused
property) for that purpose:
editor.ui.focusTracker.on( 'change:isFocused', ( evt, name, value ) => {
console.log( 'isFocused = ', value );
} );
Note that editor.ui.focusTracker.isFocused
is true
as long as any UI has focus, which includes the editable but also the toolbar, floating panels, etc.
To determine the focus of the editable, i.e. when the caret is blinking and typing is possible, use this listener instead:
editor.editing.view.document.on( 'change:isFocused', ( evt, name, value ) => {
console.log( 'editable isFocused =', value );
} );
Place one listener next to the other and play with the editor and the UI to see the difference.
本文标签: javascriptHow to listen to focus event in CKEditor 5Stack Overflow
版权声明:本文标题:javascript - How to listen to focus event in CKEditor 5 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741987441a2408766.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论