浏览代码

Clear contents of cells in multi-cell selection on CTRL-X.

Maciej Gołaszewski 5 年之前
父节点
当前提交
97f36d8d5c
共有 2 个文件被更改,包括 19 次插入12 次删除
  1. 3 0
      packages/ckeditor5-table/src/tableclipboard.js
  2. 16 12
      packages/ckeditor5-table/tests/tableclipboard.js

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

@@ -9,6 +9,7 @@
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import TableSelection from './tableselection';
+import { clearTableCellsContents } from './tableselection/utils';
 
 /**
  * The table clipboard integration plugin.
@@ -92,6 +93,8 @@ export default class TableClipboard extends Plugin {
 		if ( this._tableSelection.hasMultiCellSelection ) {
 			data.preventDefault();
 			evt.stop();
+
+			clearTableCellsContents( this.editor.model, this._tableSelection.getSelectedTableCells() );
 		}
 	}
 }

+ 16 - 12
packages/ckeditor5-table/tests/tableclipboard.js

@@ -5,7 +5,7 @@
 
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
-import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 import TableEditing from '../src/tableediting';
 import { modelTable, viewTable } from './_utils/utils';
@@ -13,6 +13,7 @@ import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
 import ViewDocumentFragment from '@ckeditor/ckeditor5-engine/src/view/documentfragment';
 import { stringify as stringifyView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 import TableClipboard from '../src/tableclipboard';
+import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'table clipboard', () => {
 	let editor, model, modelRoot, tableSelection, viewDocument;
@@ -271,37 +272,40 @@ describe( 'table clipboard', () => {
 		} );
 
 		describe( 'cut', () => {
-			it( 'is disabled for multi-range selection over a table', () => {
+			it( 'is not disabled normal selection over a table', () => {
 				const dataTransferMock = createDataTransfer();
-				const preventDefaultSpy = sinon.spy();
 				const spy = sinon.spy();
 
 				viewDocument.on( 'clipboardOutput', spy );
 
-				tableSelection.startSelectingFrom( modelRoot.getNodeByPath( [ 0, 0, 1 ] ) );
-				tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 1, 2 ] ) );
-
 				viewDocument.fire( 'cut', {
 					dataTransfer: dataTransferMock,
-					preventDefault: preventDefaultSpy
+					preventDefault: sinon.spy()
 				} );
 
-				sinon.assert.notCalled( spy );
-				sinon.assert.calledOnce( preventDefaultSpy );
+				sinon.assert.calledOnce( spy );
 			} );
 
-			it( 'is not disabled normal selection over a table', () => {
+			it( 'is clears selected table cells', () => {
 				const dataTransferMock = createDataTransfer();
+				const preventDefaultSpy = sinon.spy();
 				const spy = sinon.spy();
 
 				viewDocument.on( 'clipboardOutput', spy );
 
+				tableSelection.startSelectingFrom( modelRoot.getNodeByPath( [ 0, 0, 0 ] ) );
+				tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 1, 1 ] ) );
+
 				viewDocument.fire( 'cut', {
 					dataTransfer: dataTransferMock,
-					preventDefault: sinon.spy()
+					preventDefault: preventDefaultSpy
 				} );
 
-				sinon.assert.calledOnce( spy );
+				assertEqualMarkup( getModelData( model ), modelTable( [
+					[ { contents: '', isSelected: true }, { contents: '', isSelected: true }, '02' ],
+					[ { contents: '', isSelected: true }, { contents: '', isSelected: true }, '12' ],
+					[ '20', '21', '22' ]
+				] ) );
 			} );
 		} );
 	} );