8
0
Просмотр исходного кода

Added: Table post fixer should react on paragraph attribute change.

Maciej Gołaszewski 7 лет назад
Родитель
Сommit
f91a68c188
1 измененных файлов с 34 добавлено и 1 удалено
  1. 34 1
      packages/ckeditor5-table/src/tableediting.js

+ 34 - 1
packages/ckeditor5-table/src/tableediting.js

@@ -262,7 +262,40 @@ function paragraphInTableCellPostFixer( writer, model, mapper ) {
 	const changes = model.document.differ.getChanges();
 	const changes = model.document.differ.getChanges();
 
 
 	for ( const entry of changes ) {
 	for ( const entry of changes ) {
-		const tableCell = entry.position.parent;
+		const tableCell = entry.position && entry.position.parent;
+
+		if ( !tableCell && entry.type == 'attribute' && entry.range.start.parent.name == 'tableCell' ) {
+			const tableCell = entry.range.start.parent;
+
+			if ( tableCell.childCount === 1 ) {
+				const singleChild = tableCell.getChild( 0 );
+
+				if ( !singleChild || !singleChild.is( 'paragraph' ) ) {
+					return;
+				}
+
+				const viewElement = mapper.toViewElement( singleChild );
+
+				let renameTo = 'p';
+
+				if ( viewElement.name === 'p' ) {
+					if ( [ ...singleChild.getAttributes() ].length ) {
+						return;
+					} else {
+						renameTo = 'span';
+					}
+				}
+
+				const renamedViewElement = writer.rename( viewElement, renameTo );
+
+				// Re-bind table cell to renamed view element.
+				mapper.bindElements( singleChild, renamedViewElement );
+			}
+		}
+
+		if ( !tableCell ) {
+			continue;
+		}
 
 
 		if ( tableCell.is( 'tableCell' ) ) {
 		if ( tableCell.is( 'tableCell' ) ) {
 			if ( tableCell.childCount > 1 ) {
 			if ( tableCell.childCount > 1 ) {