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

Ensured the MouseSelectionHandler#_isSelecting flag is set false after the mouseup. Made the flag private.

Aleksander Nowodzinski 5 лет назад
Родитель
Сommit
b9cc414b55

+ 6 - 4
packages/ckeditor5-table/src/tableselection/mouseselectionhandler.js

@@ -40,10 +40,11 @@ export default class MouseSelectionHandler {
 		 * 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 a user moves a mouse over a table while holding a mouse button down.
 		 *
+		 * @private
 		 * @readonly
 		 * @member {Boolean}
 		 */
-		this.isSelecting = false;
+		this._isSelecting = false;
 
 		/**
 		 * Editing mapper.
@@ -77,12 +78,11 @@ export default class MouseSelectionHandler {
 
 		if ( !tableCell ) {
 			this._tableSelection.clearSelection();
-			this._tableSelection.stopSelection();
 
 			return;
 		}
 
-		this.isSelecting = true;
+		this._isSelecting = true;
 		this._tableSelection.startSelectingFrom( tableCell );
 	}
 
@@ -119,10 +119,12 @@ export default class MouseSelectionHandler {
 	 * @private
 	 */
 	_handleMouseUp( domEventData ) {
-		if ( !this.isSelecting ) {
+		if ( !this._isSelecting ) {
 			return;
 		}
 
+		this._isSelecting = false;
+
 		const tableCell = this._getModelTableCellFromDomEvent( domEventData );
 
 		// Selection can be stopped if table cell is undefined.

+ 24 - 0
packages/ckeditor5-table/tests/tableselection/mouseselectionhandler.js

@@ -12,10 +12,13 @@ import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils'
 import TableEditing from '../../src/tableediting';
 import TableSelection from '../../src/tableselection';
 import { assertSelectedCells, modelTable, viewTable } from '../_utils/utils';
+import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
 describe( 'table selection', () => {
 	let editor, model, view, viewDoc;
 
+	testUtils.createSinonSandbox();
+
 	beforeEach( async () => {
 		editor = await VirtualTestEditor.create( {
 			plugins: [ TableEditing, TableSelection, Paragraph ]
@@ -418,6 +421,27 @@ describe( 'table selection', () => {
 				[ '10', '11' ]
 			], { asWidget: true } ) + '<p>{}foo</p>' );
 		} );
+
+		// https://github.com/ckeditor/ckeditor5/issues/6353
+		it( 'should do nothing on successive "mouseup" events beyond the table after the selection was fininished', () => {
+			const spy = testUtils.sinon.spy( editor.plugins.get( 'TableSelection' ), 'stopSelection' );
+
+			setModelData( model, modelTable( [
+				[ '[]00', '01' ],
+				[ '10', '11' ]
+			] ) );
+
+			pressMouseButtonOver( getTableCell( '00' ) );
+			movePressedMouseOver( getTableCell( '11' ) );
+			releaseMouseButtonOver( getTableCell( '11' ) );
+
+			sinon.assert.calledOnce( spy );
+
+			pressMouseButtonOver( viewDoc.getRoot() );
+			releaseMouseButtonOver( viewDoc.getRoot() );
+
+			sinon.assert.calledOnce( spy );
+		} );
 	} );
 
 	function getTableCell( data ) {