Explorar o código

Internal: Adjusted the code to recent table selection changes on master branch (remove row command).

Marek Lewandowski %!s(int64=5) %!d(string=hai) anos
pai
achega
c84afa0645

+ 12 - 7
packages/ckeditor5-table/src/commands/removerowcommand.js

@@ -118,15 +118,20 @@ export default class RemoveRowCommand extends Command {
 	 */
 	* _getReferenceCells() {
 		const plugins = this.editor.plugins;
-		if ( plugins.has( 'TableSelection' ) && plugins.get( 'TableSelection' ).hasMultiCellSelection ) {
-			for ( const cell of plugins.get( 'TableSelection' ).getSelectedTableCells() ) {
-				yield cell;
-			}
-		} else {
-			const selection = this.editor.model.document.selection;
+		if ( plugins.has( 'TableSelection' ) ) {
+			const selectedCells = plugins.get( 'TableSelection' ).getSelectedTableCells();
+
+			if ( selectedCells ) {
+				for ( const cell of selectedCells ) {
+					yield cell;
+				}
 
-			yield findAncestor( 'tableCell', selection.getFirstPosition() );
+				return;
+			}
 		}
+
+		const selection = this.editor.model.document.selection;
+		yield findAncestor( 'tableCell', selection.getFirstPosition() );
 	}
 }
 

+ 28 - 14
packages/ckeditor5-table/tests/commands/removerowcommand.js

@@ -48,8 +48,10 @@ describe( 'RemoveRowCommand', () => {
 
 			const tableSelection = editor.plugins.get( TableSelection );
 			const modelRoot = model.document.getRoot();
-			tableSelection.startSelectingFrom( modelRoot.getNodeByPath( [ 0, 0, 0 ] ) );
-			tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 0, 1 ] ) );
+			tableSelection._setCellSelection(
+				modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
+				modelRoot.getNodeByPath( [ 0, 0, 1 ] )
+			);
 
 			expect( command.isEnabled ).to.be.true;
 		} );
@@ -94,8 +96,10 @@ describe( 'RemoveRowCommand', () => {
 
 			const tableSelection = editor.plugins.get( TableSelection );
 			const modelRoot = model.document.getRoot();
-			tableSelection.startSelectingFrom( modelRoot.getNodeByPath( [ 0, 1, 0 ] ) );
-			tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 1, 1 ] ) );
+			tableSelection._setCellSelection(
+				modelRoot.getNodeByPath( [ 0, 1, 0 ] ),
+				modelRoot.getNodeByPath( [ 0, 1, 1 ] )
+			);
 
 			command.execute();
 
@@ -116,8 +120,10 @@ describe( 'RemoveRowCommand', () => {
 
 				const tableSelection = editor.plugins.get( TableSelection );
 				const modelRoot = model.document.getRoot();
-				tableSelection.startSelectingFrom( modelRoot.getNodeByPath( [ 0, 1, 0 ] ) );
-				tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 2, 0 ] ) );
+				tableSelection._setCellSelection(
+					modelRoot.getNodeByPath( [ 0, 1, 0 ] ),
+					modelRoot.getNodeByPath( [ 0, 2, 0 ] )
+				);
 
 				command.execute();
 
@@ -139,8 +145,10 @@ describe( 'RemoveRowCommand', () => {
 
 			// 	const tableSelection = editor.plugins.get( TableSelection );
 			// 	const modelRoot = model.document.getRoot();
-			// 	tableSelection.startSelectingFrom( modelRoot.getNodeByPath( [ 0, 2, 0 ] ) );
-			// 	tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 36, 0 ] ) );
+			// tableSelection._setCellSelection(
+			// 	modelRoot.getNodeByPath( [ 0, 2, 0 ] ),
+			// 	modelRoot.getNodeByPath( [ 0, 36, 0 ] )
+			// );
 
 			// 	command.execute();
 
@@ -160,8 +168,10 @@ describe( 'RemoveRowCommand', () => {
 
 				const tableSelection = editor.plugins.get( TableSelection );
 				const modelRoot = model.document.getRoot();
-				tableSelection.startSelectingFrom( modelRoot.getNodeByPath( [ 0, 0, 0 ] ) );
-				tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 1, 0 ] ) );
+				tableSelection._setCellSelection(
+					modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
+					modelRoot.getNodeByPath( [ 0, 1, 0 ] )
+				);
 
 				command.execute();
 
@@ -181,8 +191,10 @@ describe( 'RemoveRowCommand', () => {
 
 				const tableSelection = editor.plugins.get( TableSelection );
 				const modelRoot = model.document.getRoot();
-				tableSelection.startSelectingFrom( modelRoot.getNodeByPath( [ 0, 0, 0 ] ) );
-				tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 1, 0 ] ) );
+				tableSelection._setCellSelection(
+					modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
+					modelRoot.getNodeByPath( [ 0, 1, 0 ] )
+				);
 
 				command.execute();
 
@@ -201,8 +213,10 @@ describe( 'RemoveRowCommand', () => {
 
 				const tableSelection = editor.plugins.get( TableSelection );
 				const modelRoot = model.document.getRoot();
-				tableSelection.startSelectingFrom( modelRoot.getNodeByPath( [ 0, 0, 0 ] ) );
-				tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 1, 0 ] ) );
+				tableSelection._setCellSelection(
+					modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
+					modelRoot.getNodeByPath( [ 0, 1, 0 ] )
+				);
 
 				command.execute();