8
0
Piotrek Koszuliński 5 лет назад
Родитель
Сommit
92e9de7f3f

+ 7 - 11
packages/ckeditor5-table/src/tableselection.js

@@ -352,12 +352,13 @@ export default class TableSelection extends Plugin {
 
 			const rangeToSelect = model.schema.getNearestSelectionRange( writer.createPositionAt( tableCellToSelect, 0 ) );
 
-			if ( rangeToSelect ) {
-				if ( selection.is( 'documentSelection' ) ) {
-					writer.setSelection( rangeToSelect );
-				} else {
-					selection.setTo( rangeToSelect );
-				}
+			// Note: we ignore the case where rangeToSelect may be null because deleteContent() will always (unless someone broke it)
+			// create an empty paragraph to accommodate the selection.
+
+			if ( selection.is( 'documentSelection' ) ) {
+				writer.setSelection( rangeToSelect );
+			} else {
+				selection.setTo( rangeToSelect );
 			}
 		} );
 	}
@@ -395,11 +396,6 @@ export default class TableSelection extends Plugin {
 		const modelPosition = this.editor.editing.mapper.toModelPosition( viewPosition );
 		const modelElement = modelPosition.parent;
 
-		// TODO: Required?
-		if ( !modelElement ) {
-			return;
-		}
-
 		if ( modelElement.is( 'tableCell' ) ) {
 			return modelElement;
 		}

+ 0 - 50
packages/ckeditor5-table/tests/tableselection-integration.js

@@ -104,56 +104,6 @@ describe( 'TableSelection - integration', () => {
 				[ '31', '32', '33' ]
 			] ) );
 		} );
-
-		it( 'should work with any arbitrary selection passed to Model#deleteContent() (delete backwards)', () => {
-			const selection = model.createSelection( [
-				model.createRange(
-					model.createPositionFromPath( modelRoot, [ 0, 0, 0 ] ),
-					model.createPositionFromPath( modelRoot, [ 0, 0, 1 ] )
-				),
-				model.createRange(
-					model.createPositionFromPath( modelRoot, [ 0, 0, 1 ] ),
-					model.createPositionFromPath( modelRoot, [ 0, 0, 2 ] )
-				)
-			] );
-
-			model.change( writer => {
-				model.deleteContent( selection );
-				writer.setSelection( selection );
-			} );
-
-			assertEqualMarkup( getModelData( model ), modelTable( [
-				[ '', '[]', '13' ],
-				[ '21', '22', '23' ],
-				[ '31', '32', '33' ]
-			] ) );
-		} );
-
-		it( 'should work with any arbitrary selection passed to Model#deleteContent() (delete forwards)', () => {
-			const selection = model.createSelection( [
-				model.createRange(
-					model.createPositionFromPath( modelRoot, [ 0, 0, 0 ] ),
-					model.createPositionFromPath( modelRoot, [ 0, 0, 1 ] )
-				),
-				model.createRange(
-					model.createPositionFromPath( modelRoot, [ 0, 0, 1 ] ),
-					model.createPositionFromPath( modelRoot, [ 0, 0, 2 ] )
-				)
-			] );
-
-			model.change( writer => {
-				model.deleteContent( selection, {
-					direction: 'forward'
-				} );
-				writer.setSelection( selection );
-			} );
-
-			assertEqualMarkup( getModelData( model ), modelTable( [
-				[ '[]', '', '13' ],
-				[ '21', '22', '23' ],
-				[ '31', '32', '33' ]
-			] ) );
-		} );
 	} );
 
 	describe( 'on user input', () => {

+ 86 - 0
packages/ckeditor5-table/tests/tableselection.js

@@ -67,6 +67,25 @@ describe( 'table selection', () => {
 				expect( ranges[ 0 ].start.path ).to.deep.equal( [ 0, 0, 0, 0, 0 ] );
 			} );
 
+			it( 'should reenable table selection when reenabling the plugin', () => {
+				tableSelection.forceDisabled( 'foo' );
+				tableSelection.clearForceDisabled( 'foo' );
+
+				const firstCell = modelRoot.getNodeByPath( [ 0, 0, 0 ] );
+				const lastCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
+
+				tableSelection._setCellSelection(
+					firstCell,
+					lastCell
+				);
+
+				assertSelectedCells( model, [
+					[ 1, 1, 0 ],
+					[ 1, 1, 0 ],
+					[ 0, 0, 0 ]
+				] );
+			} );
+
 			it( 'should do nothing if there were no multi-cell selections', () => {
 				tableSelection.forceDisabled( 'foo' );
 
@@ -743,6 +762,73 @@ describe( 'table selection', () => {
 				[ '31', '32', '33' ]
 			] ) );
 		} );
+
+		it( 'should work with document selection passed to Model#deleteContent()', () => {
+			tableSelection._setCellSelection(
+				modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
+				modelRoot.getNodeByPath( [ 0, 1, 1 ] )
+			);
+
+			model.change( () => {
+				model.deleteContent( model.document.selection );
+			} );
+
+			assertEqualMarkup( getModelData( model ), modelTable( [
+				[ '', '', '13' ],
+				[ '', '[]', '23' ],
+				[ '31', '32', '33' ]
+			] ) );
+		} );
+
+		it( 'should work with any arbitrary selection passed to Model#deleteContent() (delete backwards)', () => {
+			const selection = model.createSelection( [
+				model.createRange(
+					model.createPositionFromPath( modelRoot, [ 0, 0, 0 ] ),
+					model.createPositionFromPath( modelRoot, [ 0, 0, 1 ] )
+				),
+				model.createRange(
+					model.createPositionFromPath( modelRoot, [ 0, 0, 1 ] ),
+					model.createPositionFromPath( modelRoot, [ 0, 0, 2 ] )
+				)
+			] );
+
+			model.change( writer => {
+				model.deleteContent( selection );
+				writer.setSelection( selection );
+			} );
+
+			assertEqualMarkup( getModelData( model ), modelTable( [
+				[ '', '[]', '13' ],
+				[ '21', '22', '23' ],
+				[ '31', '32', '33' ]
+			] ) );
+		} );
+
+		it( 'should work with any arbitrary selection passed to Model#deleteContent() (delete forwards)', () => {
+			const selection = model.createSelection( [
+				model.createRange(
+					model.createPositionFromPath( modelRoot, [ 0, 0, 0 ] ),
+					model.createPositionFromPath( modelRoot, [ 0, 0, 1 ] )
+				),
+				model.createRange(
+					model.createPositionFromPath( modelRoot, [ 0, 0, 1 ] ),
+					model.createPositionFromPath( modelRoot, [ 0, 0, 2 ] )
+				)
+			] );
+
+			model.change( writer => {
+				model.deleteContent( selection, {
+					direction: 'forward'
+				} );
+				writer.setSelection( selection );
+			} );
+
+			assertEqualMarkup( getModelData( model ), modelTable( [
+				[ '[]', '', '13' ],
+				[ '21', '22', '23' ],
+				[ '31', '32', '33' ]
+			] ) );
+		} );
 	} );
 
 	function createEditor() {