浏览代码

Perserving writer priority when wrapping elements that can be merged.

Szymon Kupś 8 年之前
父节点
当前提交
d84d16a3ac
共有 2 个文件被更改,包括 24 次插入9 次删除
  1. 0 7
      packages/ckeditor5-engine/src/view/writer.js
  2. 24 2
      packages/ckeditor5-engine/tests/view/writer/wrap.js

+ 0 - 7
packages/ckeditor5-engine/src/view/writer.js

@@ -990,12 +990,6 @@ function shouldABeOutsideB( a, b ) {
 		return false;
 	}
 
-	// Two attribute elements with same priority and name will be merged into one element so there is no need to preserve
-	// order in such situations.
-	if ( a.name == b.name ) {
-		return true;
-	}
-
 	// When priorities are equal and names are different - use identities.
 	return a.getIdentity() < b.getIdentity();
 }
@@ -1071,7 +1065,6 @@ function mergeTextNodes( t1, t2 ) {
 }
 
 // Wraps one {@link module:engine/view/attributeelement~AttributeElement AttributeElement} into another by merging them if possible.
-// Two AttributeElements can be merged when there is no attribute or style conflicts between them.
 // When merging is possible - all attributes, styles and classes are moved from wrapper element to element being
 // wrapped.
 //

+ 24 - 2
packages/ckeditor5-engine/tests/view/writer/wrap.js

@@ -215,10 +215,10 @@ describe( 'writer', () => {
 
 		it( 'should not merge attributes when they differ', () => {
 			test(
-				'<container:p>[<attribute:b view-priority="1" foo="bar"></attribute:b>]</container:p>',
+				'<container:p>[<attribute:b view-priority="1" foo="bar">text</attribute:b>]</container:p>',
 				'<attribute:b view-priority="1" foo="baz"></attribute:b>',
 				'<container:p>' +
-					'[<attribute:b view-priority="1" foo="baz"><attribute:b view-priority="1" foo="bar"></attribute:b></attribute:b>]' +
+					'[<attribute:b view-priority="1" foo="bar"><attribute:b view-priority="1" foo="baz">text</attribute:b></attribute:b>]' +
 				'</container:p>'
 			);
 		} );
@@ -340,5 +340,27 @@ describe( 'writer', () => {
 				'</container:p>'
 			);
 		} );
+
+		it( 'should keep stable hierarchy when wrapping with attribute with same priority that can\'t be merged', () => {
+			test(
+				'<container:p>[<attribute:span name="foo">foo</attribute:span>]</container:p>',
+				'<attribute:span name="bar"></attribute:span>',
+				'<container:p>' +
+					'[<attribute:span view-priority="10" name="bar">' +
+						'<attribute:span view-priority="10" name="foo">foo</attribute:span>' +
+					'</attribute:span>]' +
+				'</container:p>'
+			);
+
+			test(
+				'<container:p>[<attribute:span name="bar">foo</attribute:span>]</container:p>',
+				'<attribute:span name="foo"></attribute:span>',
+				'<container:p>' +
+					'[<attribute:span view-priority="10" name="bar">' +
+						'<attribute:span view-priority="10" name="foo">foo</attribute:span>' +
+					'</attribute:span>]' +
+				'</container:p>'
+			);
+		} );
 	} );
 } );