Browse Source

Internal: Fixed cases where inverted selections would not work correctly with remove column / row commands.

Marek Lewandowski 5 năm trước cách đây
mục cha
commit
c716199959

+ 7 - 2
packages/ckeditor5-table/src/commands/removecolumncommand.js

@@ -52,11 +52,16 @@ export default class RemoveColumnCommand extends Command {
 		const model = this.editor.model;
 		const model = this.editor.model;
 
 
 		const referenceCells = Array.from( this._getReferenceCells() );
 		const referenceCells = Array.from( this._getReferenceCells() );
-		const firstCell = referenceCells[ 0 ];
-		const lastCell = referenceCells[ referenceCells.length - 1 ];
+		let firstCell = referenceCells[ 0 ];
+		let lastCell = referenceCells[ referenceCells.length - 1 ];
 		const tableRow = firstCell.parent;
 		const tableRow = firstCell.parent;
 		const table = tableRow.parent;
 		const table = tableRow.parent;
 
 
+		if ( firstCell.isAfter( lastCell ) ) {
+			firstCell = lastCell;
+			lastCell = referenceCells[ 0 ];
+		}
+
 		// Cache the table before removing or updating colspans.
 		// Cache the table before removing or updating colspans.
 		const tableMap = [ ...new TableWalker( table ) ];
 		const tableMap = [ ...new TableWalker( table ) ];
 
 

+ 6 - 0
packages/ckeditor5-table/src/commands/removerowcommand.js

@@ -54,6 +54,12 @@ export default class RemoveRowCommand extends Command {
 			first: referenceCells[ 0 ].parent.index,
 			first: referenceCells[ 0 ].parent.index,
 			last: referenceCells[ referenceCells.length - 1 ].parent.index
 			last: referenceCells[ referenceCells.length - 1 ].parent.index
 		};
 		};
+
+		if ( removedRowIndexes.last < removedRowIndexes.first ) {
+			removedRowIndexes.first = referenceCells[ referenceCells.length - 1 ].parent.index;
+			removedRowIndexes.last = referenceCells[ 0 ].parent.index;
+		}
+
 		const firstCell = referenceCells[ 0 ];
 		const firstCell = referenceCells[ 0 ];
 		const table = firstCell.parent.parent;
 		const table = firstCell.parent.parent;
 		const tableMap = [ ...new TableWalker( table, { endRow: removedRowIndexes.last } ) ];
 		const tableMap = [ ...new TableWalker( table, { endRow: removedRowIndexes.last } ) ];

+ 25 - 0
packages/ckeditor5-table/tests/commands/removecolumncommand.js

@@ -252,6 +252,31 @@ describe( 'RemoveColumnCommand', () => {
 				] ) );
 				] ) );
 			} );
 			} );
 
 
+			it( 'should properly remove two middle columns with reversed selection', () => {
+				setData( model, modelTable( [
+					[ '00', '01', '02', '03' ],
+					[ '10', '11', '12', '13' ],
+					[ '20', '21', '22', '23' ],
+					[ '30', '31', '32', '33' ]
+				] ) );
+
+				const tableSelection = editor.plugins.get( TableSelection );
+				const modelRoot = model.document.getRoot();
+				tableSelection._setCellSelection(
+					modelRoot.getNodeByPath( [ 0, 2, 2 ] ),
+					modelRoot.getNodeByPath( [ 0, 1, 1 ] )
+				);
+
+				command.execute();
+
+				assertEqualMarkup( getData( model ), modelTable( [
+					[ '00', '03' ],
+					[ '10', '13' ],
+					[ '20', '[]23' ],
+					[ '30', '33' ]
+				] ) );
+			} );
+
 			it( 'should properly remove two last columns', () => {
 			it( 'should properly remove two last columns', () => {
 				// There's no handling for selection in case like that.
 				// There's no handling for selection in case like that.
 				setData( model, modelTable( [
 				setData( model, modelTable( [

+ 23 - 0
packages/ckeditor5-table/tests/commands/removerowcommand.js

@@ -150,6 +150,29 @@ describe( 'RemoveRowCommand', () => {
 				] ) );
 				] ) );
 			} );
 			} );
 
 
+			it( 'should properly remove middle rows in reversed order', () => {
+				setData( model, modelTable( [
+					[ '00', '01' ],
+					[ '10', '11' ],
+					[ '20', '21' ],
+					[ '30', '31' ]
+				] ) );
+
+				const tableSelection = editor.plugins.get( TableSelection );
+				const modelRoot = model.document.getRoot();
+				tableSelection._setCellSelection(
+					modelRoot.getNodeByPath( [ 0, 2, 0 ] ),
+					modelRoot.getNodeByPath( [ 0, 1, 0 ] )
+				);
+
+				command.execute();
+
+				assertEqualMarkup( getData( model ), modelTable( [
+					[ '00', '01' ],
+					[ '[]30', '31' ]
+				] ) );
+			} );
+
 			// This test is blocked by (#6370).
 			// This test is blocked by (#6370).
 			//
 			//
 			// it( 'should properly remove tailing rows', () => {
 			// it( 'should properly remove tailing rows', () => {