8
0
Pārlūkot izejas kodu

Merge pull request #275 from ckeditor/i/6402

Internal: Cutting a table with multiple selected cells in the read-only mode should not be possible. Closes ckeditor/ckeditor5#6402.
Aleksander Nowodzinski 5 gadi atpakaļ
vecāks
revīzija
f7d84b122b

+ 4 - 0
packages/ckeditor5-table/src/tableclipboard.js

@@ -57,6 +57,10 @@ export default class TableClipboard extends Plugin {
 			return;
 		}
 
+		if ( evt.name == 'cut' && this.editor.isReadOnly ) {
+			return;
+		}
+
 		data.preventDefault();
 		evt.stop();
 

+ 28 - 0
packages/ckeditor5-table/tests/tableclipboard.js

@@ -360,6 +360,34 @@ describe( 'table clipboard', () => {
 					[ '11', '12' ]
 				] ) );
 			} );
+
+			it( 'should be disabled in a readonly mode', () => {
+				const preventDefaultStub = sinon.stub();
+
+				editor.isReadOnly = true;
+
+				tableSelection._setCellSelection(
+					modelRoot.getNodeByPath( [ 0, 0, 1 ] ),
+					modelRoot.getNodeByPath( [ 0, 1, 2 ] )
+				);
+
+				const data = {
+					dataTransfer: createDataTransfer(),
+					preventDefault: preventDefaultStub
+				};
+				viewDocument.fire( 'cut', data );
+
+				editor.isReadOnly = false;
+
+				expect( data.dataTransfer.getData( 'text/html' ) ).to.be.undefined;
+				assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
+					[ '00', '01', '02' ],
+					[ '10', '11', '12' ],
+					[ '20', '21', '22' ]
+				] ) );
+
+				sinon.assert.calledOnce( preventDefaultStub );
+			} );
 		} );
 	} );