Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Brought back copy/cut.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Mar 5, 2020
1 parent 0c910fd commit b04ac3e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 177 deletions.
15 changes: 3 additions & 12 deletions src/tableclipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ export default class TableClipboard extends Plugin {
const editor = this.editor;
const viewDocument = editor.editing.view.document;

/**
* A table selection plugin instance.
*
* @private
* @readonly
* @member {module:table/tableselection~TableSelection} module:tableclipboard~TableClipboard#_tableSelection
*/
this._tableSelection = editor.plugins.get( 'TableSelection' );

this.listenTo( viewDocument, 'copy', ( evt, data ) => this._onCopyCut( evt, data ) );
this.listenTo( viewDocument, 'cut', ( evt, data ) => this._onCopyCut( evt, data ) );
}
Expand All @@ -60,9 +51,9 @@ export default class TableClipboard extends Plugin {
* @private
*/
_onCopyCut( evt, data ) {
const tableSelection = this._tableSelection;
const tableSelection = this.editor.plugins.get( 'TableSelection' );

if ( !tableSelection.hasMultiCellSelection ) {
if ( !tableSelection.getSelectedTableCells() ) {
return;
}

Expand All @@ -72,7 +63,7 @@ export default class TableClipboard extends Plugin {
const dataController = this.editor.data;
const viewDocument = this.editor.editing.view.document;

const content = dataController.toView( this._tableSelection.getSelectionAsFragment() );
const content = dataController.toView( tableSelection.getSelectionAsFragment() );

viewDocument.fire( 'clipboardOutput', {
dataTransfer: data.dataTransfer,
Expand Down
17 changes: 17 additions & 0 deletions src/tableselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import TableUtils from './tableutils';
import MouseEventsObserver from './tableselection/mouseeventsobserver';
import { getTableCellsInSelection, clearTableCellsContents } from './tableselection/utils';
import { findAncestor } from './commands/utils';
import cropTable from './tableselection/croptable';

import '../theme/tableselection.css';

Expand Down Expand Up @@ -79,6 +80,22 @@ export default class TableSelection extends Plugin {
return selectedCells;
}

/**
* Returns a selected table fragment as a document fragment.
*
* @returns {module:engine/model/documentfragment~DocumentFragment}
*/
getSelectionAsFragment() {
return this.editor.model.change( writer => {
const documentFragment = writer.createDocumentFragment();
const table = cropTable( this.getSelectedTableCells(), this.editor.plugins.get( 'TableUtils' ), writer );

writer.insert( table, documentFragment, 0 );

return documentFragment;
} );
}

/**
* Defines a selection converter which marks selected cells with a specific class.
*
Expand Down
165 changes: 0 additions & 165 deletions src/tableselection/mouseselectionhandler.js

This file was deleted.

0 comments on commit b04ac3e

Please sign in to comment.