|
|
@@ -94,6 +94,7 @@ export default class TableSelection extends Plugin {
|
|
|
init() {
|
|
|
const editor = this.editor;
|
|
|
const selection = editor.model.document.selection;
|
|
|
+ const viewDocument = editor.editing.view.document;
|
|
|
|
|
|
this._tableUtils = editor.plugins.get( 'TableUtils' );
|
|
|
|
|
|
@@ -101,27 +102,8 @@ export default class TableSelection extends Plugin {
|
|
|
|
|
|
selection.on( 'change:range', () => this._clearSelectionOnExternalChange( selection ) );
|
|
|
|
|
|
- this.listenTo( editor.editing.view.document, 'copy', ( evt, data ) => {
|
|
|
- if ( !this.hasMultiCellSelection ) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const dataTransfer = data.dataTransfer;
|
|
|
-
|
|
|
- data.preventDefault();
|
|
|
- evt.stop();
|
|
|
-
|
|
|
- const content = editor.data.toView( this.getSelectionAsFragment() );
|
|
|
-
|
|
|
- editor.editing.view.document.fire( 'clipboardOutput', { dataTransfer, content, method: evt.name } );
|
|
|
- }, { priority: 'normal' } );
|
|
|
-
|
|
|
- this.listenTo( editor.editing.view.document, 'cut', ( evt, data ) => {
|
|
|
- if ( this.hasMultiCellSelection ) {
|
|
|
- data.preventDefault();
|
|
|
- evt.stop();
|
|
|
- }
|
|
|
- }, { priority: 'high' } );
|
|
|
+ this.listenTo( viewDocument, 'copy', createTableCopyHandler( this, editor ), { priority: 'normal' } );
|
|
|
+ this.listenTo( viewDocument, 'cut', createPreventTableCutHandler( this ), { priority: 'high' } );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -296,3 +278,31 @@ export default class TableSelection extends Plugin {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+function createPreventTableCutHandler( tableSelection ) {
|
|
|
+ return ( evt, data ) => {
|
|
|
+ if ( tableSelection.hasMultiCellSelection ) {
|
|
|
+ data.preventDefault();
|
|
|
+ evt.stop();
|
|
|
+ }
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+function createTableCopyHandler( tableSelection, editor ) {
|
|
|
+ return ( evt, data ) => {
|
|
|
+ if ( !tableSelection.hasMultiCellSelection ) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ data.preventDefault();
|
|
|
+ evt.stop();
|
|
|
+
|
|
|
+ const content = editor.data.toView( tableSelection.getSelectionAsFragment() );
|
|
|
+
|
|
|
+ editor.editing.view.document.fire( 'clipboardOutput', {
|
|
|
+ dataTransfer: data.dataTransfer,
|
|
|
+ content,
|
|
|
+ method: evt.name
|
|
|
+ } );
|
|
|
+ };
|
|
|
+}
|