Kaynağa Gözat

Internal: Extracted soon-to-be-reused range utility. Minor cleanup in one unit test.

Marek Lewandowski 5 yıl önce
ebeveyn
işleme
f3c17dcc57

+ 1 - 8
packages/ckeditor5-table/src/commands/insertcolumncommand.js

@@ -8,7 +8,7 @@
  */
 
 import Command from '@ckeditor/ckeditor5-core/src/command';
-import { findAncestor } from './utils';
+import { getRangeContainedElement, findAncestor } from './utils';
 
 /**
  * The insert column command.
@@ -81,12 +81,5 @@ export default class InsertColumnCommand extends Command {
 		const { column } = tableUtils.getCellLocation( tableCell );
 
 		tableUtils.insertColumns( table, { columns: 1, at: insertBefore ? column : column + 1 } );
-
-		function getRangeContainedElement( range ) {
-			const nodeAfterStart = range.start.nodeAfter;
-			const nodeBeforeEnd = range.end.nodeBefore;
-
-			return ( nodeAfterStart && nodeAfterStart.is( 'element' ) && nodeAfterStart == nodeBeforeEnd ) ? nodeAfterStart : null;
-		}
 	}
 }

+ 13 - 0
packages/ckeditor5-table/src/commands/utils.js

@@ -29,6 +29,19 @@ export function findAncestor( parentName, positionOrElement ) {
 	}
 }
 
+/**
+ * Returns an element contained by a range, if it's the only one element contained by the range and if it's fully contained.
+ *
+ * @param {module:engine/model/range~Range} range
+ * @returns {module:engine/model/element~Element|null}
+ */
+export function getRangeContainedElement( range ) {
+	const nodeAfterStart = range.start.nodeAfter;
+	const nodeBeforeEnd = range.end.nodeBefore;
+
+	return ( nodeAfterStart && nodeAfterStart.is( 'element' ) && nodeAfterStart == nodeBeforeEnd ) ? nodeAfterStart : null;
+}
+
 /**
  * A common method to update the numeric value. If a value is the default one, it will be unset.
  *

+ 1 - 1
packages/ckeditor5-table/tests/commands/insertcolumncommand.js

@@ -94,7 +94,7 @@ describe( 'InsertColumnCommand', () => {
 			it( 'should insert column after a multi column selection', () => {
 				setData( model, modelTable( [
 					[ '11', '12', '13' ],
-					[ '21', '22[]', '23' ]
+					[ '21', '22', '23' ]
 				] ) );
 
 				const tableSelection = editor.plugins.get( TableSelection );