我想听Ckeditor 5中的焦点事件。
我以为这样的事情会起作用,但是回调从未被调用:
document.querySelector("#editable");
ClassicEditor.create(el).then(editor => {
editor.on('focus', () => {
console.log("Focused");
});
});
编辑器已成功创建,但未调用回调。
有什么想法?
编辑器带有FocusTracker
(和可观察的#isFocused
属性(出于此目的:
editor.ui.focusTracker.on( 'change:isFocused', ( evt, name, value ) => {
console.log( 'isFocused = ', value );
} );
请注意,editor.ui.focusTracker.isFocused
是true
,只要任何UI 都有焦点,其中包括可编辑但工具栏,浮动面板等。
要确定可编辑的焦点,即,何时可能会闪烁和打字时,请改用此侦听器:
editor.editing.view.document.on( 'change:isFocused', ( evt, name, value ) => {
console.log( 'editable isFocused =', value );
} );
将一个听众放在另一个旁边,并与编辑器和UI一起播放以查看差异。