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

Stop selection on mouse move if button was depressed outside webpage.

Maciej Gołaszewski 6 лет назад
Родитель
Сommit
220587f468

+ 2 - 14
packages/ckeditor5-table/src/tableselection.js

@@ -42,15 +42,6 @@ export default class TableSelection extends Plugin {
 	constructor( editor ) {
 		super( editor );
 
-		/**
-		 * A flag indicating that the selection is "active". A selection is "active" if it was started and not yet finished.
-		 * A selection can be "active" for instance if user moves a mouse over a table while holding a mouse button down.
-		 *
-		 * @readonly
-		 * @member {Boolean}
-		 */
-		this.isSelecting = false;
-
 		/**
 		 * A mouse selection handler.
 		 *
@@ -107,7 +98,6 @@ export default class TableSelection extends Plugin {
 	startSelectingFrom( tableCell ) {
 		this.clearSelection();
 
-		this.isSelecting = true;
 		this._startElement = tableCell;
 		this._endElement = tableCell;
 	}
@@ -124,7 +114,7 @@ export default class TableSelection extends Plugin {
 	 */
 	setSelectingTo( tableCell ) {
 		// Do not update if not in selection mode or no table cell is passed.
-		if ( !this.isSelecting || !tableCell ) {
+		if ( !tableCell ) {
 			return;
 		}
 
@@ -151,11 +141,10 @@ export default class TableSelection extends Plugin {
 	 * @param {module:engine/model/element~Element} [tableCell]
 	 */
 	stopSelection( tableCell ) {
-		if ( this.isSelecting && tableCell && tableCell.parent.parent === this._startElement.parent.parent ) {
+		if ( tableCell && tableCell.parent.parent === this._startElement.parent.parent ) {
 			this._endElement = tableCell;
 		}
 
-		this.isSelecting = false;
 		this._updateModelSelection();
 	}
 
@@ -171,7 +160,6 @@ export default class TableSelection extends Plugin {
 	clearSelection() {
 		this._startElement = undefined;
 		this._endElement = undefined;
-		this.isSelecting = false;
 	}
 
 	/**

+ 19 - 3
packages/ckeditor5-table/src/tableselection/mouseselectionhandler.js

@@ -36,6 +36,15 @@ export default class MouseSelectionHandler {
 		 */
 		this._tableSelection = tableSelection;
 
+		/**
+		 * A flag indicating that the mouse selection is "active". A selection is "active" if it was started and not yet finished.
+		 * A selection can be "active" for instance if user moves a mouse over a table while holding a mouse button down.
+		 *
+		 * @readonly
+		 * @member {Boolean}
+		 */
+		this.isSelecting = false;
+
 		/**
 		 * Editing mapper.
 		 *
@@ -74,6 +83,7 @@ export default class MouseSelectionHandler {
 			return;
 		}
 
+		this.isSelecting = true;
 		this._tableSelection.startSelectingFrom( tableCell );
 	}
 
@@ -86,9 +96,11 @@ export default class MouseSelectionHandler {
 	 * @private
 	 */
 	_handleMouseMove( domEventData ) {
-		// if ( !this._tableSelection.isSelecting ) {
-		// 	return;
-		// }
+		if ( !isButtonPressed( domEventData ) ) {
+			this._tableSelection.stopSelection();
+
+			return;
+		}
 
 		const tableCell = this._getModelTableCellFromDomEvent( domEventData );
 
@@ -157,4 +169,8 @@ export default class MouseSelectionHandler {
 	}
 }
 
+function isButtonPressed( domEventData ) {
+	return !!domEventData.domEvent.buttons;
+}
+
 mix( MouseSelectionHandler, ObservableMixin );