8
0
Maciej Gołaszewski 7 лет назад
Родитель
Сommit
990013838a

+ 6 - 6
packages/ckeditor5-table/src/commands/mergecellcommand.js

@@ -72,19 +72,19 @@ export default class MergeCellCommand extends Command {
 			const isMergeNext = direction == 'right' || direction == 'down';
 
 			// The merge mechanism is always the same so sort cells to be merged.
-			const mergeInto = isMergeNext ? tableCell : cellToMerge;
-			const removeCell = isMergeNext ? cellToMerge : tableCell;
+			const cellToExpand = isMergeNext ? tableCell : cellToMerge;
+			const cellToRemove = isMergeNext ? cellToMerge : tableCell;
 
-			writer.move( Range.createIn( removeCell ), Position.createAt( mergeInto, 'end' ) );
-			writer.remove( removeCell );
+			writer.move( Range.createIn( cellToRemove ), Position.createAt( cellToExpand, 'end' ) );
+			writer.remove( cellToRemove );
 
 			const spanAttribute = this.isHorizontal ? 'colspan' : 'rowspan';
 			const cellSpan = parseInt( tableCell.getAttribute( spanAttribute ) || 1 );
 			const cellToMergeSpan = parseInt( cellToMerge.getAttribute( spanAttribute ) || 1 );
 
-			writer.setAttribute( spanAttribute, cellSpan + cellToMergeSpan, mergeInto );
+			writer.setAttribute( spanAttribute, cellSpan + cellToMergeSpan, cellToExpand );
 
-			writer.setSelection( Range.createIn( mergeInto ) );
+			writer.setSelection( Range.createIn( cellToExpand ) );
 		} );
 	}
 

+ 15 - 21
packages/ckeditor5-table/src/converters/downcast.js

@@ -117,9 +117,10 @@ export function downcastInsertRow( options = {} ) {
 }
 
 /**
- * Model row element to view <tr> element conversion helper.
+ * Model tableCEll element to view <td> or <th> element conversion helper.
  *
- * This conversion helper creates whole <tr> element with child elements.
+ * This conversion helper will create proper <th> elements for tableCells that are in heading section (heading row or column)
+ * and <td> otherwise.
  *
  * @returns {Function} Conversion helper.
  */
@@ -279,30 +280,23 @@ export function downcastRemoveRow() {
 		// Prevent default remove converter.
 		evt.stop();
 
-		let viewStart = conversionApi.mapper.toViewPosition( data.position );
-
-		const modelEnd = data.position.getShiftedBy( data.length );
-		let viewEnd = conversionApi.mapper.toViewPosition( modelEnd, { isPhantom: true } );
+		const viewStart = conversionApi.mapper.toViewPosition( data.position ).getLastMatchingPosition( value => !value.item.is( 'tr' ) );
+		const viewItem = viewStart.nodeAfter;
+		const tableSection = viewItem.parent;
 
-		// Make sure that start and end positions are inside the same parent as default remove converter doesn't work well with
-		// wrapped elements: https://github.com/ckeditor/ckeditor5-engine/issues/1414
-		if ( viewStart.parent !== viewEnd.parent ) {
-			if ( viewStart.parent.name == 'table' ) {
-				viewStart = ViewPosition.createAt( viewEnd.parent );
-			}
-
-			if ( viewEnd.parent.name == 'table' ) {
-				viewEnd = ViewPosition.createAt( viewStart.parent, 'end' );
-			}
-		}
-
-		const viewRange = new ViewRange( viewStart, viewEnd );
-
-		const removed = conversionApi.writer.remove( viewRange.getTrimmed() );
+		// Remove associated <tr> from the view.
+		const removeRange = ViewRange.createOn( viewItem );
+		const removed = conversionApi.writer.remove( removeRange );
 
 		for ( const child of ViewRange.createIn( removed ).getItems() ) {
 			conversionApi.mapper.unbindViewElement( child );
 		}
+
+		// Check if table section has any children left - if not remove it from the view.
+		if ( !tableSection.childCount ) {
+			// No need to unbind anything as table section is not represented in the model.
+			conversionApi.writer.remove( ViewRange.createOn( tableSection ) );
+		}
 	}, { priority: 'higher' } );
 }
 

+ 1 - 5
packages/ckeditor5-table/src/tableutils.js

@@ -551,11 +551,7 @@ function createEmptyRows( writer, table, insertAt, rows, tableCellToInsert, attr
 
 		writer.insert( tableRow, table, insertAt );
 
-		for ( let columnIndex = 0; columnIndex < tableCellToInsert; columnIndex++ ) {
-			const cell = writer.createElement( 'tableCell', attributes );
-
-			writer.insert( cell, tableRow, 'end' );
-		}
+		createCells( tableCellToInsert, writer, Position.createAt( tableRow, 'end' ), attributes );
 	}
 }