8
0
Просмотр исходного кода

Changed. Make TableSelection a plugin.

Maciej Gołaszewski 7 лет назад
Родитель
Сommit
2529773500

+ 3 - 7
packages/ckeditor5-table/src/tableediting.js

@@ -151,10 +151,7 @@ export default class TableEditing extends Plugin {
 		this.editor.keystrokes.set( 'Tab', this._getTabHandler( true ), { priority: 'low' } );
 		this.editor.keystrokes.set( 'Shift+Tab', this._getTabHandler( false ), { priority: 'low' } );
 
-		const selected = new Set();
-
-		const tableUtils = editor.plugins.get( TableUtils );
-		const tableSelection = new TableSelection( editor, tableUtils );
+		const tableSelection = editor.plugins.get( TableSelection );
 
 		this.listenTo( viewDocument, 'mousedown', ( eventInfo, domEventData ) => {
 			const tableCell = getTableCell( domEventData, this.editor );
@@ -163,7 +160,7 @@ export default class TableEditing extends Plugin {
 				return;
 			}
 
-			const { column, row } = tableUtils.getCellLocation( tableCell );
+			const { column, row } = editor.plugins.get( TableUtils ).getCellLocation( tableCell );
 
 			const mode = getSelectionMode( domEventData, column, row );
 
@@ -206,7 +203,6 @@ export default class TableEditing extends Plugin {
 
 				if ( node && ( node.is( 'td' ) || node.is( 'th' ) ) ) {
 					editor.editing.view.change( writer => writer.addClass( 'selected', node ) );
-					selected.add( node );
 				}
 			}
 		} );
@@ -216,7 +212,7 @@ export default class TableEditing extends Plugin {
 	 * @inheritDoc
 	 */
 	static get requires() {
-		return [ TableUtils ];
+		return [ TableUtils, TableSelection ];
 	}
 
 	/**

+ 22 - 3
packages/ckeditor5-table/src/tableselection.js

@@ -8,15 +8,34 @@
  */
 
 import ViewRange from '@ckeditor/ckeditor5-engine/src/view/range';
+import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+
 import TableWalker from './tablewalker';
+import TableUtils from './tableutils';
+
+export default class TableSelection extends Plugin {
+	/**
+	 * @inheritDoc
+	 */
+	static get pluginName() {
+		return 'TableSelection';
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	static get requires() {
+		return [ TableUtils ];
+	}
+
+	constructor( editor ) {
+		super( editor );
 
-export default class TableSelection {
-	constructor( editor, tableUtils ) {
 		this._isSelecting = false;
 		this._highlighted = new Set();
 
 		this.editor = editor;
-		this.tableUtils = tableUtils;
+		this.tableUtils = editor.plugins.get( TableUtils );
 	}
 
 	get isSelecting() {