8
0
فهرست منبع

Update typing after changes in the engine.

Piotr Jasiun 8 سال پیش
والد
کامیت
b813a47ef7

+ 2 - 1
packages/ckeditor5-typing/src/changebuffer.js

@@ -8,6 +8,7 @@
  */
  */
 
 
 import count from '@ckeditor/ckeditor5-utils/src/count';
 import count from '@ckeditor/ckeditor5-utils/src/count';
+import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';
 
 
 /**
 /**
  * Change buffer allows to group atomic changes (like characters that have been typed) into
  * Change buffer allows to group atomic changes (like characters that have been typed) into
@@ -112,7 +113,7 @@ export default class ChangeBuffer {
 	 */
 	 */
 	get batch() {
 	get batch() {
 		if ( !this._batch ) {
 		if ( !this._batch ) {
-			this._batch = this.document.batch();
+			this._batch = new Batch();
 		}
 		}
 
 
 		return this._batch;
 		return this._batch;

+ 17 - 14
packages/ckeditor5-typing/src/deletecommand.js

@@ -61,10 +61,11 @@ export default class DeleteCommand extends Command {
 	 * See the {@link module:engine/view/document~Document#event:delete} event data.
 	 * See the {@link module:engine/view/document~Document#event:delete} event data.
 	 */
 	 */
 	execute( options = {} ) {
 	execute( options = {} ) {
-		const doc = this.editor.document;
+		const model = this.editor.model;
+		const doc = model.document;
 		const dataController = this.editor.data;
 		const dataController = this.editor.data;
 
 
-		doc.enqueueChanges( () => {
+		model.enqueueChange( this._buffer.batch, writer => {
 			this._buffer.lock();
 			this._buffer.lock();
 
 
 			const selection = Selection.createFromSelection( doc.selection );
 			const selection = Selection.createFromSelection( doc.selection );
@@ -83,7 +84,7 @@ export default class DeleteCommand extends Command {
 
 
 			// Check if deleting in an empty editor. See #61.
 			// Check if deleting in an empty editor. See #61.
 			if ( this._shouldEntireContentBeReplacedWithParagraph( options.sequence || 1 ) ) {
 			if ( this._shouldEntireContentBeReplacedWithParagraph( options.sequence || 1 ) ) {
-				this._replaceEntireContentWithParagraph();
+				this._replaceEntireContentWithParagraph( writer );
 
 
 				return;
 				return;
 			}
 			}
@@ -101,7 +102,7 @@ export default class DeleteCommand extends Command {
 				);
 				);
 			} );
 			} );
 
 
-			dataController.deleteContent( selection, this._buffer.batch, { doNotResetEntireContent } );
+			dataController.deleteContent( selection, { doNotResetEntireContent } );
 			this._buffer.input( changeCount );
 			this._buffer.input( changeCount );
 
 
 			doc.selection.setRanges( selection.getRanges(), selection.isBackward );
 			doc.selection.setRanges( selection.getRanges(), selection.isBackward );
@@ -134,9 +135,10 @@ export default class DeleteCommand extends Command {
 			return false;
 			return false;
 		}
 		}
 
 
-		const document = this.editor.document;
-		const selection = document.selection;
-		const limitElement = document.schema.getLimitElement( selection );
+		const model = this.editor.model;
+		const doc = model.document;
+		const selection = doc.selection;
+		const limitElement = model.schema.getLimitElement( selection );
 
 
 		// If a collapsed selection contains the whole content it means that the content is empty
 		// If a collapsed selection contains the whole content it means that the content is empty
 		// (from the user perspective).
 		// (from the user perspective).
@@ -146,7 +148,7 @@ export default class DeleteCommand extends Command {
 			return false;
 			return false;
 		}
 		}
 
 
-		if ( !document.schema.check( { name: 'paragraph', inside: limitElement.name } ) ) {
+		if ( !model.schema.check( { name: 'paragraph', inside: limitElement.name } ) ) {
 			return false;
 			return false;
 		}
 		}
 
 
@@ -167,14 +169,15 @@ export default class DeleteCommand extends Command {
 	 *
 	 *
 	 * @private
 	 * @private
 	 */
 	 */
-	_replaceEntireContentWithParagraph() {
-		const document = this.editor.document;
-		const selection = document.selection;
-		const limitElement = document.schema.getLimitElement( selection );
+	_replaceEntireContentWithParagraph( writer ) {
+		const model = this.editor.model;
+		const doc = model.document;
+		const selection = doc.selection;
+		const limitElement = model.schema.getLimitElement( selection );
 		const paragraph = new Element( 'paragraph' );
 		const paragraph = new Element( 'paragraph' );
 
 
-		this._buffer.batch.remove( Range.createIn( limitElement ) );
-		this._buffer.batch.insert( paragraph, limitElement );
+		writer.remove( Range.createIn( limitElement ) );
+		writer.insert( paragraph, limitElement );
 
 
 		selection.setCollapsedAt( paragraph );
 		selection.setCollapsedAt( paragraph );
 	}
 	}

+ 5 - 5
packages/ckeditor5-typing/src/input.js

@@ -68,7 +68,8 @@ export default class Input extends Plugin {
 	 * @param {module:typing/inputcommand~InputCommand} inputCommand
 	 * @param {module:typing/inputcommand~InputCommand} inputCommand
 	 */
 	 */
 	_handleKeydown( evtData, inputCommand ) {
 	_handleKeydown( evtData, inputCommand ) {
-		const doc = this.editor.document;
+		const model = this.editor.model;
+		const doc = this.model.document;
 		const buffer = inputCommand.buffer;
 		const buffer = inputCommand.buffer;
 
 
 		// By relying on the state of the input command we allow disabling the entire input easily
 		// By relying on the state of the input command we allow disabling the entire input easily
@@ -86,8 +87,8 @@ export default class Input extends Plugin {
 
 
 		buffer.lock();
 		buffer.lock();
 
 
-		doc.enqueueChanges( () => {
-			this.editor.data.deleteContent( doc.selection, buffer.batch );
+		model.enqueueChange( buffer.batch, () => {
+			this.editor.data.deleteContent( doc.selection );
 		} );
 		} );
 
 
 		buffer.unlock();
 		buffer.unlock();
@@ -194,8 +195,7 @@ class MutationHandler {
 		// This wouldn't be needed if DomConverter would allow to create fresh view without checking any mappings.
 		// This wouldn't be needed if DomConverter would allow to create fresh view without checking any mappings.
 		const freshDomConverter = new DomConverter();
 		const freshDomConverter = new DomConverter();
 		const modelFromCurrentDom = this.editor.data.toModel(
 		const modelFromCurrentDom = this.editor.data.toModel(
-			freshDomConverter.domToView( domMutationCommonAncestor ),
-			this.editor.commands.get( 'input' ).buffer.batch
+			freshDomConverter.domToView( domMutationCommonAncestor )
 		).getChild( 0 );
 		).getChild( 0 );
 
 
 		// Current model.
 		// Current model.

+ 6 - 5
packages/ckeditor5-typing/src/inputcommand.js

@@ -33,7 +33,7 @@ export default class InputCommand extends Command {
 		 * @private
 		 * @private
 		 * @member {module:typing/changebuffer~ChangeBuffer} #_buffer
 		 * @member {module:typing/changebuffer~ChangeBuffer} #_buffer
 		 */
 		 */
-		this._buffer = new ChangeBuffer( editor.document, undoStepSize );
+		this._buffer = new ChangeBuffer( editor.model.document, undoStepSize );
 	}
 	}
 
 
 	/**
 	/**
@@ -69,23 +69,24 @@ export default class InputCommand extends Command {
 	 * the inserted text.
 	 * the inserted text.
 	 */
 	 */
 	execute( options = {} ) {
 	execute( options = {} ) {
-		const doc = this.editor.document;
+		const model = this.editor.model;
+		const doc = this.model.document;
 		const text = options.text || '';
 		const text = options.text || '';
 		const textInsertions = text.length;
 		const textInsertions = text.length;
 		const range = options.range || doc.selection.getFirstRange();
 		const range = options.range || doc.selection.getFirstRange();
 		const resultRange = options.resultRange;
 		const resultRange = options.resultRange;
 
 
-		doc.enqueueChanges( () => {
+		model.enqueueChange( this._buffer.batch, writer => {
 			const isCollapsedRange = range.isCollapsed;
 			const isCollapsedRange = range.isCollapsed;
 
 
 			this._buffer.lock();
 			this._buffer.lock();
 
 
 			if ( !isCollapsedRange ) {
 			if ( !isCollapsedRange ) {
-				this._buffer.batch.remove( range );
+				writer.remove( range );
 			}
 			}
 
 
 			if ( text ) {
 			if ( text ) {
-				this._buffer.batch.insertText( text, doc.selection.getAttributes(), range.start );
+				writer.insertText( text, doc.selection.getAttributes(), range.start );
 			}
 			}
 
 
 			if ( resultRange ) {
 			if ( resultRange ) {