瀏覽代碼

Changed: Do not change tables in table selection mode.

Maciej Gołaszewski 7 年之前
父節點
當前提交
32ec9ac78a
共有 1 個文件被更改,包括 30 次插入28 次删除
  1. 30 28
      packages/ckeditor5-table/src/tableediting.js

+ 30 - 28
packages/ckeditor5-table/src/tableediting.js

@@ -341,40 +341,16 @@ class TableSelection {
 	}
 
 	updateSelection( tableCell ) {
-		this._endElement = tableCell;
-		this._redrawSelection();
-	}
-
-	_redrawSelection() {
-		const viewRanges = [];
-
-		const selected = [ ...this.getSelection() ];
-		const previous = [ ...this._highlighted.values() ];
-
-		this._highlighted.clear();
-
-		for ( const tableCell of selected ) {
-			const viewElement = this.editor.editing.mapper.toViewElement( tableCell );
-			viewRanges.push( ViewRange.createOn( viewElement ) );
-
-			this._highlighted.add( viewElement );
+		if ( tableCell && tableCell.parent.parent === this._startElement.parent.parent ) {
+			this._endElement = tableCell;
 		}
-
-		this.editor.editing.view.change( writer => {
-			for ( const previouslyHighlighted of previous ) {
-				if ( !selected.includes( previouslyHighlighted ) ) {
-					writer.removeClass( 'selected', previouslyHighlighted );
-				}
-			}
-
-			writer.setSelection( viewRanges, { fake: true, label: 'fake selection over table cell' } );
-		} );
+		this._redrawSelection();
 	}
 
 	stopSelection( tableCell ) {
 		this._isSelecting = false;
 
-		if ( tableCell ) {
+		if ( tableCell && tableCell.parent.parent === this._startElement.parent.parent ) {
 			this._endElement = tableCell;
 		}
 
@@ -452,6 +428,32 @@ class TableSelection {
 			}
 		}
 	}
+
+	_redrawSelection() {
+		const viewRanges = [];
+
+		const selected = [ ...this.getSelection() ];
+		const previous = [ ...this._highlighted.values() ];
+
+		this._highlighted.clear();
+
+		for ( const tableCell of selected ) {
+			const viewElement = this.editor.editing.mapper.toViewElement( tableCell );
+			viewRanges.push( ViewRange.createOn( viewElement ) );
+
+			this._highlighted.add( viewElement );
+		}
+
+		this.editor.editing.view.change( writer => {
+			for ( const previouslyHighlighted of previous ) {
+				if ( !selected.includes( previouslyHighlighted ) ) {
+					writer.removeClass( 'selected', previouslyHighlighted );
+				}
+			}
+
+			writer.setSelection( viewRanges, { fake: true, label: 'fake selection over table cell' } );
+		} );
+	}
 }
 
 function getTableCell( domEventData, editor ) {