浏览代码

Schema extended with allowMultiRangeSelection flag.

Kuba Niegowski 5 年之前
父节点
当前提交
5733acbca2

+ 3 - 3
packages/ckeditor5-engine/src/model/schema.js

@@ -1490,7 +1490,7 @@ function compileBaseItemRule( sourceItemRules, itemName ) {
 		inheritTypesFrom: []
 	};
 
-	copyTypes( sourceItemRules, itemRule );
+	copyTypesAndFlags( sourceItemRules, itemRule );
 
 	copyProperty( sourceItemRules, itemRule, 'allowIn' );
 	copyProperty( sourceItemRules, itemRule, 'allowContentOf' );
@@ -1585,9 +1585,9 @@ function cleanUpAllowAttributes( compiledDefinitions, itemName ) {
 	itemRule.allowAttributes = Array.from( new Set( itemRule.allowAttributes ) );
 }
 
-function copyTypes( sourceItemRules, itemRule ) {
+function copyTypesAndFlags( sourceItemRules, itemRule ) {
 	for ( const sourceItemRule of sourceItemRules ) {
-		const typeNames = Object.keys( sourceItemRule ).filter( name => name.startsWith( 'is' ) );
+		const typeNames = Object.keys( sourceItemRule ).filter( name => name.startsWith( 'is' ) || name == 'allowMultiRangeSelection' );
 
 		for ( const name of typeNames ) {
 			itemRule[ name ] = sourceItemRule[ name ];

+ 2 - 9
packages/ckeditor5-table/src/tableediting.js

@@ -77,7 +77,8 @@ export default class TableEditing extends Plugin {
 		schema.register( 'tableCell', {
 			allowIn: 'tableRow',
 			allowAttributes: [ 'colspan', 'rowspan' ],
-			isObject: true
+			isObject: true,
+			allowMultiRangeSelection: true
 		} );
 
 		// Allow all $block content inside table cell.
@@ -146,14 +147,6 @@ export default class TableEditing extends Plugin {
 		injectTableLayoutPostFixer( model );
 		injectTableCellRefreshPostFixer( model );
 		injectTableCellParagraphPostFixer( model );
-
-		const undoElementsWithSeparateSelectionRanges = editor.config.get( 'undo.elementsWithSeparateSelectionRanges' ) || [];
-
-		if ( !undoElementsWithSeparateSelectionRanges.includes( 'tableCell' ) ) {
-			undoElementsWithSeparateSelectionRanges.push( 'tableCell' );
-
-			editor.config.set( 'undo.elementsWithSeparateSelectionRanges', undoElementsWithSeparateSelectionRanges );
-		}
 	}
 
 	/**

+ 5 - 1
packages/ckeditor5-undo/src/basecommand.js

@@ -89,6 +89,10 @@ export default class BaseCommand extends Command {
 		const model = this.editor.model;
 		const document = model.document;
 
+		const elementsExpectingSeparateSelectionRange = Object.values( model.schema.getDefinitions() )
+			.filter( ( { allowMultiRangeSelection } ) => allowMultiRangeSelection )
+			.map( ( { name } ) => name );
+
 		// Transform all ranges from the restored selection.
 		const selectionRanges = ranges
 			.flatMap( range => range.getTransformedByOperations( operations ) )
@@ -96,7 +100,7 @@ export default class BaseCommand extends Command {
 			.sort( ( a, b ) => a.start.isBefore( b.start ) ? -1 : 1 );
 
 		normalizeRanges( selectionRanges );
-		normalizeRanges( selectionRanges, this.editor.config.get( 'undo.elementsWithSeparateSelectionRanges' ) || [] );
+		normalizeRanges( selectionRanges, elementsExpectingSeparateSelectionRange );
 
 		// @if CK_DEBUG_ENGINE // console.log( `Restored selection from undo: ${ selectionRanges.join( ', ' ) }` );
 

+ 0 - 2
packages/ckeditor5-undo/src/undoediting.js

@@ -55,8 +55,6 @@ export default class UndoEditing extends Plugin {
 		 * @member {WeakSet.<module:engine/model/batch~Batch>}
 		 */
 		this._batchRegistry = new WeakSet();
-
-		editor.config.define( 'undo.elementsWithSeparateSelectionRanges', [] );
 	}
 
 	/**