Browse Source

The isBlockFiller() should allow single   inside inline elements.

Maciej Gołaszewski 6 years ago
parent
commit
a1b55e4e1f

+ 10 - 3
packages/ckeditor5-engine/src/view/filler.js

@@ -142,7 +142,7 @@ export function isBlockFiller( domNode, blockFiller ) {
 
 	const isFiller = domNode.isEqualNode( templateBlockFiller );
 
-	return isText( templateBlockFiller ) ? isFiller && !hasInlineSibling( domNode ) : isFiller;
+	return isText( templateBlockFiller ) ? isFiller && !hasInlineSiblingOrParent( domNode ) : isFiller;
 }
 
 /**
@@ -175,13 +175,20 @@ function jumpOverInlineFiller( evt, data ) {
 //
 // @param {Node} domNode DOM node.
 // @returns {Boolean}
-function hasInlineSibling( domNode ) {
+function hasInlineSiblingOrParent( domNode ) {
 	const hasParent = !!domNode.parentNode;
 
-	if ( !hasParent || domNode.parentNode.childNodes.length <= 1 ) {
+
+	if ( !hasParent ) {
 		return false;
 	}
 
+	const isSingleNode = hasParent && domNode.parentNode.childNodes.length <= 1;
+
+	if ( isSingleNode ) {
+		return isInlineElement( domNode.parentNode );
+	}
+
 	const prevIsInline = isInlineElement( domNode.previousSibling );
 	const nextIsInline = isInlineElement( domNode.nextSibling );
 

+ 26 - 27
packages/ckeditor5-engine/tests/dataprocessor/htmldataprocessor.js

@@ -59,33 +59,32 @@ describe( 'HtmlDataProcessor', () => {
 			} );
 		}
 
-		// Uncomment this test after fixing #404.
-		// describe( 'https://github.com/ckeditor/ckeditor5-clipboard/issues/2#issuecomment-310417731 + #404', () => {
-		// 	it( 'does not lose whitespaces in Chrome\'s paste-like content', () => {
-		// 		const fragment = dataProcessor.toView(
-		// 			'<meta charset=\'utf-8\'>' +
-		// 			'<span>This is the<span>\u00a0</span></span>' +
-		// 			'<a href="url">third developer preview</a>' +
-		// 			'<span><span>\u00a0</span>of<span>\u00a0</span></span>' +
-		// 			'<strong>CKEditor\u00a05</strong>' +
-		// 			'<span>.</span>'
-		// 		);
-
-		// 		expect( stringify( fragment ) ).to.equal(
-		// 			'<span>This is the<span>\u00a0</span></span>' +
-		// 			'<a href="url">third developer preview</a>' +
-		// 			'<span><span>\u00a0</span>of<span>\u00a0</span></span>' +
-		// 			'<strong>CKEditor\u00a05</strong>' +
-		// 			'<span>.</span>'
-		// 		);
-
-		// 		// Just to be sure... stringify() uses conversion and the browser extensively,
-		// 		// so it's not entirely safe.
-		// 		expect( fragment.getChild( 0 ).getChild( 1 ).getChild( 0 ).data ).to.equal( '\u00a0' );
-		// 		expect( fragment.getChild( 2 ).getChild( 0 ).getChild( 0 ).data ).to.equal( '\u00a0' );
-		// 		expect( fragment.getChild( 2 ).getChild( 2 ).getChild( 0 ).data ).to.equal( '\u00a0' );
-		// 	} );
-		// } );
+		describe( 'https://github.com/ckeditor/ckeditor5-clipboard/issues/2#issuecomment-310417731 + #404', () => {
+			it( 'does not lose whitespaces in Chrome\'s paste-like content', () => {
+				const fragment = dataProcessor.toView(
+					'<meta charset=\'utf-8\'>' +
+					'<span>This is the<span>\u00a0</span></span>' +
+					'<a href="url">third developer preview</a>' +
+					'<span><span>\u00a0</span>of<span>\u00a0</span></span>' +
+					'<strong>CKEditor\u00a05</strong>' +
+					'<span>.</span>'
+				);
+
+				expect( stringify( fragment ) ).to.equal(
+					'<span>This is the<span>\u00a0</span></span>' +
+					'<a href="url">third developer preview</a>' +
+					'<span><span>\u00a0</span>of<span>\u00a0</span></span>' +
+					'<strong>CKEditor\u00a05</strong>' +
+					'<span>.</span>'
+				);
+
+				// Just to be sure... stringify() uses conversion and the browser extensively,
+				// so it's not entirely safe.
+				expect( fragment.getChild( 0 ).getChild( 1 ).getChild( 0 ).data ).to.equal( '\u00a0' );
+				expect( fragment.getChild( 2 ).getChild( 0 ).getChild( 0 ).data ).to.equal( '\u00a0' );
+				expect( fragment.getChild( 2 ).getChild( 2 ).getChild( 0 ).data ).to.equal( '\u00a0' );
+			} );
+		} );
 	} );
 
 	describe( 'toData()', () => {