我已经创建了一个自定义插件,如图所示.我可以添加类为"PlaceHolder"的对象.<span class="placeholder">Loop-ANS(Q2)</span>
美元.
创建自的内联构件 Created from个
现在,当有人从编辑器中删除此项时,我需要生成一个事件(调用一个函数),以便我可以标记此项已在我的Redux状态中删除.我用下面的代码得到了这个问题的解决方案.
editor.model.document.on( 'change:data', () => { // Listen to all changes in model.
// Get changes buffered in Differ. Include items moved to the graveyard (removed from document).
const changes = editor.model.document.differ.getChanges( { includeChangesInGraveyard: true } );
for ( const change of changes ) {
// Check items moved to the graveyard (so they are removed from the document root).
if ( change.type == 'insert' && change.name != '$text' && change.position.root.rootName == '$graveyard' ) {
// The element that we are looking for could be nested in some block-quote or a table cell
// so we need to walk through the whole element content and check if our element was removed or not.
const range = editor.model.createRangeOn( change.position.nodeAfter );
for ( const item of range.getItems() ) {
if ( item.is( 'element', 'imageInline' ) ) { // Here you change the value to your element's name.
console.log( 'inline image removed', item ); // (**I will add a callback here**)
}
}
}
}
} );
问题是,当我试图拖放内联小部件时,它也被视为已删除.也就是说,元素正在转移到墓地,这是不应该的. 有什么方法可以防止这种情况发生吗?该占位符在拖放到其他位置时不能在墓地上移动.或者判断事件是由于拖放而生成的,而不是调用回调.
如果不可能,有任何方法可以停止内联小工具的拖放事件