|
@@ -19,13 +19,12 @@ export default class EnterCommand extends Command {
|
|
|
* @inheritDoc
|
|
* @inheritDoc
|
|
|
*/
|
|
*/
|
|
|
execute() {
|
|
execute() {
|
|
|
- const doc = this.editor.document;
|
|
|
|
|
- const batch = doc.batch();
|
|
|
|
|
|
|
+ const model = this.editor.model;
|
|
|
|
|
+ const doc = model.document;
|
|
|
|
|
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- enterBlock( this.editor.data, batch, doc.selection, doc.schema );
|
|
|
|
|
-
|
|
|
|
|
- this.fire( 'afterExecute', { batch } );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ enterBlock( this.editor.data, writer, doc.selection, model.schema );
|
|
|
|
|
+ this.fire( 'afterExecute', { writer } );
|
|
|
} );
|
|
} );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -33,10 +32,10 @@ export default class EnterCommand extends Command {
|
|
|
// Creates a new block in the way that the <kbd>Enter</kbd> key is expected to work.
|
|
// Creates a new block in the way that the <kbd>Enter</kbd> key is expected to work.
|
|
|
//
|
|
//
|
|
|
// @param {engine.controller.DataController} dataController
|
|
// @param {engine.controller.DataController} dataController
|
|
|
-// @param {module:engine/model/batch~Batch} batch A batch to which the deltas will be added.
|
|
|
|
|
|
|
+// @param {module:engine.model/writer~Writer} writer
|
|
|
// @param {module:engine/model/selection~Selection} selection Selection on which the action should be performed.
|
|
// @param {module:engine/model/selection~Selection} selection Selection on which the action should be performed.
|
|
|
// @param {module:engine/model/schema~Schema} schema
|
|
// @param {module:engine/model/schema~Schema} schema
|
|
|
-function enterBlock( dataController, batch, selection, schema ) {
|
|
|
|
|
|
|
+function enterBlock( dataController, writer, selection, schema ) {
|
|
|
const isSelectionEmpty = selection.isCollapsed;
|
|
const isSelectionEmpty = selection.isCollapsed;
|
|
|
const range = selection.getFirstRange();
|
|
const range = selection.getFirstRange();
|
|
|
const startElement = range.start.parent;
|
|
const startElement = range.start.parent;
|
|
@@ -49,26 +48,26 @@ function enterBlock( dataController, batch, selection, schema ) {
|
|
|
// This is an edge case and it's hard to tell what should actually happen because such a selection
|
|
// This is an edge case and it's hard to tell what should actually happen because such a selection
|
|
|
// is not entirely valid.
|
|
// is not entirely valid.
|
|
|
if ( !isSelectionEmpty && startElement == endElement ) {
|
|
if ( !isSelectionEmpty && startElement == endElement ) {
|
|
|
- dataController.deleteContent( selection, batch );
|
|
|
|
|
|
|
+ dataController.deleteContent( selection );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if ( isSelectionEmpty ) {
|
|
if ( isSelectionEmpty ) {
|
|
|
- splitBlock( batch, selection, range.start );
|
|
|
|
|
|
|
+ splitBlock( writer, selection, range.start );
|
|
|
} else {
|
|
} else {
|
|
|
const leaveUnmerged = !( range.start.isAtStart && range.end.isAtEnd );
|
|
const leaveUnmerged = !( range.start.isAtStart && range.end.isAtEnd );
|
|
|
const isContainedWithinOneElement = ( startElement == endElement );
|
|
const isContainedWithinOneElement = ( startElement == endElement );
|
|
|
|
|
|
|
|
- dataController.deleteContent( selection, batch, { leaveUnmerged } );
|
|
|
|
|
|
|
+ dataController.deleteContent( selection, { leaveUnmerged } );
|
|
|
|
|
|
|
|
if ( leaveUnmerged ) {
|
|
if ( leaveUnmerged ) {
|
|
|
// Partially selected elements.
|
|
// Partially selected elements.
|
|
|
//
|
|
//
|
|
|
// <h>x[xx]x</h> -> <h>x^x</h> -> <h>x</h><h>^x</h>
|
|
// <h>x[xx]x</h> -> <h>x^x</h> -> <h>x</h><h>^x</h>
|
|
|
if ( isContainedWithinOneElement ) {
|
|
if ( isContainedWithinOneElement ) {
|
|
|
- splitBlock( batch, selection, selection.focus );
|
|
|
|
|
|
|
+ splitBlock( writer, selection, selection.focus );
|
|
|
}
|
|
}
|
|
|
// Selection over multiple elements.
|
|
// Selection over multiple elements.
|
|
|
//
|
|
//
|
|
@@ -80,7 +79,7 @@ function enterBlock( dataController, batch, selection, schema ) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function splitBlock( batch, selection, splitPos ) {
|
|
|
|
|
|
|
+function splitBlock( writer, selection, splitPos ) {
|
|
|
const oldElement = splitPos.parent;
|
|
const oldElement = splitPos.parent;
|
|
|
const newElement = new oldElement.constructor( oldElement.name, oldElement.getAttributes() );
|
|
const newElement = new oldElement.constructor( oldElement.name, oldElement.getAttributes() );
|
|
|
|
|
|
|
@@ -88,14 +87,14 @@ function splitBlock( batch, selection, splitPos ) {
|
|
|
// If the split is at the end of element, instead of splitting, just create a clone of position's parent
|
|
// If the split is at the end of element, instead of splitting, just create a clone of position's parent
|
|
|
// element and insert it after split element. The result is the same but less operations are done
|
|
// element and insert it after split element. The result is the same but less operations are done
|
|
|
// and it's more semantically correct (when it comes to operational transformation).
|
|
// and it's more semantically correct (when it comes to operational transformation).
|
|
|
- batch.insert( newElement, splitPos.parent, 'after' );
|
|
|
|
|
|
|
+ writer.insert( newElement, splitPos.parent, 'after' );
|
|
|
} else if ( splitPos.isAtStart ) {
|
|
} else if ( splitPos.isAtStart ) {
|
|
|
// If the split is at the start of element, instead of splitting, just create a clone of position's parent
|
|
// If the split is at the start of element, instead of splitting, just create a clone of position's parent
|
|
|
// element and insert it before split element. The result is the same but less operations are done
|
|
// element and insert it before split element. The result is the same but less operations are done
|
|
|
// and it's more semantically correct (when it comes to operational transformation).
|
|
// and it's more semantically correct (when it comes to operational transformation).
|
|
|
- batch.insert( newElement, splitPos.parent, 'before' );
|
|
|
|
|
|
|
+ writer.insert( newElement, splitPos.parent, 'before' );
|
|
|
} else {
|
|
} else {
|
|
|
- batch.split( splitPos );
|
|
|
|
|
|
|
+ writer.split( splitPos );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
selection.setCollapsedAt( splitPos.parent.nextSibling );
|
|
selection.setCollapsedAt( splitPos.parent.nextSibling );
|