Selaa lähdekoodia

Aligned code with the engine changes.

Oskar Wróbel 8 vuotta sitten
vanhempi
commit
03cf4b0c0a

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

@@ -8,6 +8,7 @@
  */
 
 import Command from '@ckeditor/ckeditor5-core/src/command';
+import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';
 
 /**
  * Base class for undo feature commands: {@link module:undo/undocommand~UndoCommand} and {@link module:undo/redocommand~RedoCommand}.
@@ -56,7 +57,7 @@ export default class BaseCommand extends Command {
 	 * @param {module:engine/model/batch~Batch} batch The batch to add.
 	 */
 	addBatch( batch ) {
-		const docSelection = this.editor.document.selection;
+		const docSelection = this.editor.model.document.selection;
 
 		const selection = {
 			ranges: docSelection.hasOwnRange ? Array.from( docSelection.getRanges() ) : [],
@@ -84,7 +85,7 @@ export default class BaseCommand extends Command {
 	 * @param {Array.<module:engine/model/delta/delta~Delta>} deltas Deltas which has been applied since selection has been stored.
 	 */
 	_restoreSelection( ranges, isBackward, deltas ) {
-		const document = this.editor.document;
+		const document = this.editor.model.document;
 
 		// This will keep the transformed selection ranges.
 		const selectionRanges = [];
@@ -121,10 +122,11 @@ export default class BaseCommand extends Command {
 	 * @param {module:engine/model/batch~Batch} batchToUndo The batch to be undone.
 	 */
 	_undo( batchToUndo ) {
-		const document = this.editor.document;
+		const model = this.editor.model;
+		const document = model.document;
 
 		// All changes done by the command execution will be saved as one batch.
-		const undoingBatch = document.batch();
+		const undoingBatch = new Batch();
 		this._createdBatches.add( undoingBatch );
 
 		const deltasToUndo = batchToUndo.deltas.slice();
@@ -156,7 +158,7 @@ export default class BaseCommand extends Command {
 
 					// Now, apply all operations of the delta.
 					for ( const operation of delta.operations ) {
-						document.applyOperation( operation );
+						model.applyOperation( operation );
 					}
 
 					document.history.setDeltaAsUndone( deltaToUndo, delta );

+ 2 - 2
packages/ckeditor5-undo/src/redocommand.js

@@ -33,10 +33,10 @@ export default class RedoCommand extends BaseCommand {
 
 		// All changes have to be done in one `enqueueChanges` callback so other listeners will not
 		// step between consecutive deltas, or won't do changes to the document before selection is properly restored.
-		this.editor.document.enqueueChanges( () => {
+		this.editor.model.enqueueChange( () => {
 			const lastDelta = item.batch.deltas[ item.batch.deltas.length - 1 ];
 			const nextBaseVersion = lastDelta.baseVersion + lastDelta.operations.length;
-			const deltas = this.editor.document.history.getDeltas( nextBaseVersion );
+			const deltas = this.editor.model.document.history.getDeltas( nextBaseVersion );
 
 			this._restoreSelection( item.selection.ranges, item.selection.isBackward, deltas );
 			this._undo( item.batch );

+ 2 - 2
packages/ckeditor5-undo/src/undocommand.js

@@ -36,10 +36,10 @@ export default class UndoCommand extends BaseCommand {
 
 		// All changes has to be done in one `enqueueChanges` callback so other listeners will not
 		// step between consecutive deltas, or won't do changes to the document before selection is properly restored.
-		this.editor.document.enqueueChanges( () => {
+		this.editor.model.enqueueChange( () => {
 			const undoingBatch = this._undo( item.batch );
 
-			const deltas = this.editor.document.history.getDeltas( item.batch.baseVersion );
+			const deltas = this.editor.model.document.history.getDeltas( item.batch.baseVersion );
 			this._restoreSelection( item.selection.ranges, item.selection.isBackward, deltas );
 
 			this.fire( 'revert', item.batch, undoingBatch );

+ 1 - 1
packages/ckeditor5-undo/src/undoengine.js

@@ -63,7 +63,7 @@ export default class UndoEngine extends Plugin {
 		this.editor.commands.add( 'undo', this._undoCommand );
 		this.editor.commands.add( 'redo', this._redoCommand );
 
-		this.listenTo( this.editor.document, 'change', ( evt, type, changes, batch ) => {
+		this.listenTo( this.editor.model.document, 'change', ( evt, type, changes, batch ) => {
 			// If changes are not a part of a batch or this is not a new batch, omit those changes.
 			if ( this._batchRegistry.has( batch ) || batch.type == 'transparent' ) {
 				return;