|
|
@@ -56,29 +56,46 @@ export default class MentionEditing extends Plugin {
|
|
|
editor.model.schema.extend( '$text', { allowAttributes: 'mention' } );
|
|
|
|
|
|
// Remove mention attribute if text was edited.
|
|
|
- editor.model.document.registerPostFixer( writer => {
|
|
|
- const selection = editor.model.document.selection;
|
|
|
- const focus = selection.focus;
|
|
|
-
|
|
|
- if ( selection.hasAttribute( 'mention' ) && selection.isCollapsed && focus.nodeBefore && focus.nodeBefore.is( 'text' ) ) {
|
|
|
- writer.removeSelectionAttribute( 'mention' );
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
- } );
|
|
|
-
|
|
|
editor.model.document.registerPostFixer( writer => {
|
|
|
const changes = editor.model.document.differ.getChanges();
|
|
|
|
|
|
+ let wasChanged = false;
|
|
|
+
|
|
|
for ( const change of changes ) {
|
|
|
if ( change.type == 'insert' || change.type == 'remove' ) {
|
|
|
const textNode = change.position.textNode;
|
|
|
|
|
|
if ( change.name == '$text' && textNode && textNode.hasAttribute( 'mention' ) ) {
|
|
|
writer.removeAttribute( 'mention', textNode );
|
|
|
+ wasChanged = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( change.type == 'remove' ) {
|
|
|
+ const nodeBefore = change.position.nodeBefore;
|
|
|
+
|
|
|
+ if ( nodeBefore && nodeBefore.hasAttribute( 'mention' ) ) {
|
|
|
+ const text = nodeBefore.data;
|
|
|
+ if ( text != nodeBefore.getAttribute( 'mention' ) ) {
|
|
|
+ writer.removeAttribute( 'mention', nodeBefore );
|
|
|
+ wasChanged = true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return wasChanged;
|
|
|
+ } );
|
|
|
+
|
|
|
+ editor.model.document.registerPostFixer( writer => {
|
|
|
+ const selection = editor.model.document.selection;
|
|
|
+ const focus = selection.focus;
|
|
|
+
|
|
|
+ if ( selection.hasAttribute( 'mention' ) && selection.isCollapsed && focus.nodeBefore && focus.nodeBefore.is( 'text' ) ) {
|
|
|
+ writer.removeSelectionAttribute( 'mention' );
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
} );
|
|
|
}
|
|
|
}
|