|
|
@@ -10,6 +10,7 @@
|
|
|
import Position from '../model/position';
|
|
|
import LivePosition from '../model/liveposition';
|
|
|
import Element from '../model/element';
|
|
|
+import Text from '../model/text';
|
|
|
import Range from '../model/range';
|
|
|
import log from '@ckeditor/ckeditor5-utils/src/log';
|
|
|
|
|
|
@@ -286,6 +287,14 @@ class Insertion {
|
|
|
if ( mergeLeft ) {
|
|
|
const position = LivePosition.createFromPosition( this.position );
|
|
|
|
|
|
+ const children = Array.from( node.getChildren() );
|
|
|
+
|
|
|
+ // When Text is a direct child of node which is going to be merged
|
|
|
+ // we need to strip it from the disallowed attributes according to the new parent.
|
|
|
+ if ( children.some( child => child instanceof Text ) ) {
|
|
|
+ this._stripDisallowedAttributes( children, mergePosLeft.nodeBefore );
|
|
|
+ }
|
|
|
+
|
|
|
this.batch.merge( mergePosLeft );
|
|
|
|
|
|
this.position = Position.createFromPosition( position );
|
|
|
@@ -309,6 +318,14 @@ class Insertion {
|
|
|
// NOK: <p>xx[]</p> + <p>yy</p> => <p>xxyy[]</p> (when sticks to next)
|
|
|
const position = new LivePosition( this.position.root, this.position.path, 'sticksToPrevious' );
|
|
|
|
|
|
+ const children = Array.from( node.getChildren() );
|
|
|
+
|
|
|
+ // When Text is a direct child of node which is going to be merged
|
|
|
+ // we need to strip it from the disallowed attributes according to the new parent.
|
|
|
+ if ( children.some( child => child instanceof Text ) ) {
|
|
|
+ this._stripDisallowedAttributes( children, mergePosLeft.nodeAfter );
|
|
|
+ }
|
|
|
+
|
|
|
this.batch.merge( mergePosRight );
|
|
|
|
|
|
this.position = Position.createFromPosition( position );
|
|
|
@@ -431,16 +448,22 @@ class Insertion {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Removes disallowed by schema attributes.
|
|
|
+ * Removes disallowed by schema attributes from given nodes.
|
|
|
*
|
|
|
* @private
|
|
|
- * @param {module:engine/model/node~Node} node
|
|
|
+ * @param {module:engine/model/node~Node|Array<module:engine/model/node~Node>} nodes
|
|
|
* @param {module:engine/model/schema~SchemaPath} path
|
|
|
*/
|
|
|
- _stripDisallowedAttributes( node, path = this.position ) {
|
|
|
- for ( const attribute of node.getAttributeKeys() ) {
|
|
|
- if ( !this.schema.check( { name: '$text', attributes: attribute, inside: path } ) ) {
|
|
|
- node.removeAttribute( attribute );
|
|
|
+ _stripDisallowedAttributes( nodes, path = this.position ) {
|
|
|
+ if ( !Array.isArray( nodes ) ) {
|
|
|
+ nodes = [ nodes ];
|
|
|
+ }
|
|
|
+
|
|
|
+ for ( const node of nodes ) {
|
|
|
+ for ( const attribute of node.getAttributeKeys() ) {
|
|
|
+ if ( !this.schema.check( { name: '$text', attributes: attribute, inside: path } ) ) {
|
|
|
+ node.removeAttribute( attribute );
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|