ソースを参照

Aligned code with engine changes.

Oskar Wróbel 8 年 前
コミット
d1aecba522

+ 1 - 1
packages/ckeditor5-block-quote/src/blockquote.js

@@ -78,7 +78,7 @@ export default class BlockQuote extends Plugin {
 		// We can't use a priority for this, because 'low' is already used by the enter feature, unless
 		// we'd use numeric priority in this case.
 		this.listenTo( this.editor.editing.view, 'enter', ( evt, data ) => {
-			const doc = this.editor.document;
+			const doc = this.editor.model.document;
 			const positionParent = doc.selection.getLastPosition().parent;
 
 			if ( doc.selection.isCollapsed && positionParent.isEmpty && command.value ) {

+ 20 - 23
packages/ckeditor5-block-quote/src/blockquotecommand.js

@@ -42,19 +42,16 @@ export default class BlockQuoteCommand extends Command {
 	 * a block quote.
 	 *
 	 * @fires execute
-	 * @param {Object} [options] Options for executed command.
-	 * @param {module:engine/model/batch~Batch} [options.batch] Batch to collect all the change steps.
-	 * A new batch will be created if this option is not set.
 	 */
-	execute( options = {} ) {
-		const doc = this.editor.document;
-		const schema = doc.schema;
-		const batch = options.batch || doc.batch();
+	execute() {
+		const model = this.editor.model;
+		const doc = model.document;
+		const schema = model.schema;
 		const blocks = Array.from( doc.selection.getSelectedBlocks() );
 
-		doc.enqueueChanges( () => {
+		model.change( writer => {
 			if ( this.value ) {
-				this._removeQuote( batch, blocks.filter( findQuote ) );
+				this._removeQuote( writer, blocks.filter( findQuote ) );
 			} else {
 				const blocksToQuote = blocks.filter( block => {
 					// Already quoted blocks needs to be considered while quoting too
@@ -62,7 +59,7 @@ export default class BlockQuoteCommand extends Command {
 					return findQuote( block ) || checkCanBeQuoted( schema, block );
 				} );
 
-				this._applyQuote( batch, blocksToQuote );
+				this._applyQuote( writer, blocksToQuote );
 			}
 		} );
 	}
@@ -74,7 +71,7 @@ export default class BlockQuoteCommand extends Command {
 	 * @returns {Boolean} The current value.
 	 */
 	_getValue() {
-		const firstBlock = first( this.editor.document.selection.getSelectedBlocks() );
+		const firstBlock = first( this.editor.model.document.selection.getSelectedBlocks() );
 
 		// In the current implementation, the block quote must be an immediate parent of a block element.
 		return !!( firstBlock && findQuote( firstBlock ) );
@@ -91,8 +88,8 @@ export default class BlockQuoteCommand extends Command {
 			return true;
 		}
 
-		const selection = this.editor.document.selection;
-		const schema = this.editor.document.schema;
+		const selection = this.editor.model.document.selection;
+		const schema = this.editor.model.schema;
 
 		const firstBlock = first( selection.getSelectedBlocks() );
 
@@ -111,14 +108,14 @@ export default class BlockQuoteCommand extends Command {
 	 * will be moved out of it, so other quoted blocks remained quoted.
 	 *
 	 * @private
-	 * @param {module:engine/model/batch~Batch} batch
+	 * @param {module:engine/model/writer~Writer} writer
 	 * @param {Array.<module:engine/model/element~Element>} blocks
 	 */
-	_removeQuote( batch, blocks ) {
+	_removeQuote( writer, blocks ) {
 		// Unquote all groups of block. Iterate in the reverse order to not break following ranges.
 		getRangesOfBlockGroups( blocks ).reverse().forEach( groupRange => {
 			if ( groupRange.start.isAtStart && groupRange.end.isAtEnd ) {
-				batch.unwrap( groupRange.start.parent );
+				writer.unwrap( groupRange.start.parent );
 
 				return;
 			}
@@ -127,7 +124,7 @@ export default class BlockQuoteCommand extends Command {
 			if ( groupRange.start.isAtStart ) {
 				const positionBefore = Position.createBefore( groupRange.start.parent );
 
-				batch.move( groupRange, positionBefore );
+				writer.move( groupRange, positionBefore );
 
 				return;
 			}
@@ -135,14 +132,14 @@ export default class BlockQuoteCommand extends Command {
 			// The blocks are in the middle of an <bQ> so we need to split the <bQ> after the last block
 			// so we move the items there.
 			if ( !groupRange.end.isAtEnd ) {
-				batch.split( groupRange.end );
+				writer.split( groupRange.end );
 			}
 
 			// Now we are sure that groupRange.end.isAtEnd is true, so let's move the blocks right.
 
 			const positionAfter = Position.createAfter( groupRange.end.parent );
 
-			batch.move( groupRange, positionAfter );
+			writer.move( groupRange, positionAfter );
 		} );
 	}
 
@@ -150,10 +147,10 @@ export default class BlockQuoteCommand extends Command {
 	 * Applies the quote to given blocks.
 	 *
 	 * @private
-	 * @param {module:engine/model/batch~Batch} batch
+	 * @param {module:engine/model/writer~Writer} writer
 	 * @param {Array.<module:engine/model/element~Element>} blocks
 	 */
-	_applyQuote( batch, blocks ) {
+	_applyQuote( writer, blocks ) {
 		const quotesToMerge = [];
 
 		// Quote all groups of block. Iterate in the reverse order to not break following ranges.
@@ -163,7 +160,7 @@ export default class BlockQuoteCommand extends Command {
 			if ( !quote ) {
 				quote = new Element( 'blockQuote' );
 
-				batch.wrap( groupRange, quote );
+				writer.wrap( groupRange, quote );
 			}
 
 			quotesToMerge.push( quote );
@@ -175,7 +172,7 @@ export default class BlockQuoteCommand extends Command {
 		// we want to keep the reference to the first (furthest left) one.
 		quotesToMerge.reverse().reduce( ( currentQuote, nextQuote ) => {
 			if ( currentQuote.nextSibling == nextQuote ) {
-				batch.merge( Position.createAfter( currentQuote ) );
+				writer.merge( Position.createAfter( currentQuote ) );
 
 				return currentQuote;
 			}

+ 2 - 2
packages/ckeditor5-block-quote/src/blockquoteengine.js

@@ -27,7 +27,7 @@ export default class BlockQuoteEngine extends Plugin {
 	 */
 	init() {
 		const editor = this.editor;
-		const schema = editor.document.schema;
+		const schema = editor.model.schema;
 
 		editor.commands.add( 'blockQuote', new BlockQuoteCommand( editor ) );
 
@@ -48,7 +48,7 @@ export default class BlockQuoteEngine extends Plugin {
 	 * @inheritDoc
 	 */
 	afterInit() {
-		const schema = this.editor.document.schema;
+		const schema = this.editor.model.schema;
 
 		// TODO
 		// Workaround for https://github.com/ckeditor/ckeditor5-engine/issues/532#issuecomment-280924650.