Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Changed: Remove ReinsertOperation and RemoveOperation.
Browse files Browse the repository at this point in the history
  • Loading branch information
scofalik committed Jul 30, 2018
1 parent 00fbf7f commit 49d2318
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 571 deletions.
1 change: 0 additions & 1 deletion src/model/operation/detachoperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default class DetachOperation extends Operation {
if ( this.sourcePosition.root.document ) {
/**
* Cannot detach document node.
* Use {@link module:engine/model/operation/removeoperation~RemoveOperation remove operation} instead.
*
* @error detach-operation-on-document-node
*/
Expand Down
6 changes: 3 additions & 3 deletions src/model/operation/insertoperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import Operation from './operation';
import Position from '../position';
import NodeList from '../nodelist';
import RemoveOperation from './removeoperation';
import MoveOperation from './moveoperation';
import { _insert, _normalizeNodes } from './utils';
import Text from '../text';
import Element from '../element';
Expand Down Expand Up @@ -87,13 +87,13 @@ export default class InsertOperation extends Operation {
/**
* See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
*
* @returns {module:engine/model/operation/removeoperation~RemoveOperation}
* @returns {module:engine/model/operation/moveoperation~MoveOperation}
*/
getReversed() {
const graveyard = this.position.root.document.graveyard;
const gyPosition = new Position( graveyard, [ 0 ] );

return new RemoveOperation( this.position, this.nodes.maxOffset, gyPosition, this.baseVersion + 1 );
return new MoveOperation( this.position, this.nodes.maxOffset, gyPosition, this.baseVersion + 1 );
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/model/operation/moveoperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ export default class MoveOperation extends Operation {
* @inheritDoc
*/
get type() {
if ( this.targetPosition.root.rootName == '$graveyard' ) {
return 'remove';
} else if ( this.sourcePosition.root.rootName == '$graveyard' ) {
return 'reinsert';
}

return 'move';
}

Expand Down
4 changes: 0 additions & 4 deletions src/model/operation/operationfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import MarkerOperation from '../operation/markeroperation';
import MoveOperation from '../operation/moveoperation';
import NoOperation from '../operation/nooperation';
import Operation from '../operation/operation';
import ReinsertOperation from '../operation/reinsertoperation';
import RemoveOperation from '../operation/removeoperation';
import RenameOperation from '../operation/renameoperation';
import RootAttributeOperation from '../operation/rootattributeoperation';
import SplitOperation from '../operation/splitoperation';
Expand All @@ -29,8 +27,6 @@ operations[ MarkerOperation.className ] = MarkerOperation;
operations[ MoveOperation.className ] = MoveOperation;
operations[ NoOperation.className ] = NoOperation;
operations[ Operation.className ] = Operation;
operations[ ReinsertOperation.className ] = ReinsertOperation;
operations[ RemoveOperation.className ] = RemoveOperation;
operations[ RenameOperation.className ] = RenameOperation;
operations[ RootAttributeOperation.className ] = RootAttributeOperation;
operations[ SplitOperation.className ] = SplitOperation;
Expand Down
76 changes: 0 additions & 76 deletions src/model/operation/reinsertoperation.js

This file was deleted.

60 changes: 0 additions & 60 deletions src/model/operation/removeoperation.js

This file was deleted.

55 changes: 9 additions & 46 deletions src/model/operation/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import AttributeOperation from './attributeoperation';
import RenameOperation from './renameoperation';
import MarkerOperation from './markeroperation';
import MoveOperation from './moveoperation';
import RemoveOperation from './removeoperation';
import ReinsertOperation from './reinsertoperation';
import RootAttributeOperation from './rootattributeoperation';
import MergeOperation from './mergeoperation';
import SplitOperation from './splitoperation';
Expand All @@ -29,32 +27,10 @@ function setTransformation( OperationA, OperationB, transformationFunction ) {
}

function getTransformation( a, b ) {
const OperationA = a.constructor;
const OperationB = b.constructor;
const aGroup = transformations.get( a.constructor );

const aGroups = new Set();
const aGroup = transformations.get( OperationA );

if ( aGroup ) {
aGroups.add( aGroup );
}

for ( const Operation of transformations.keys() ) {
if ( a instanceof Operation ) {
aGroups.add( transformations.get( Operation ) );
}
}

for ( const group of aGroups ) {
if ( group.has( OperationB ) ) {
return group.get( OperationB );
}

for ( const Operation of group.keys() ) {
if ( b instanceof Operation ) {
return group.get( Operation );
}
}
if ( aGroup && aGroup.has( b.constructor ) ) {
return aGroup.get( b.constructor );
}

return noUpdateTransformation;
Expand Down Expand Up @@ -707,7 +683,7 @@ setTransformation( MergeOperation, MoveOperation, ( a, b, context ) => {
//
const removedRange = Range.createFromPositionAndShift( b.sourcePosition, b.howMany );

if ( b instanceof RemoveOperation && !context.wasUndone( b ) ) {
if ( b.type == 'remove' && !context.wasUndone( b ) ) {
if ( a.deletionPosition.hasSameParentAs( b.sourcePosition ) && removedRange.containsPosition( a.sourcePosition ) ) {
return getNoOp();
}
Expand Down Expand Up @@ -926,9 +902,9 @@ setTransformation( MoveOperation, MoveOperation, ( a, b, context ) => {
//
// If only one of operations is a remove operation, we force remove operation to be the "stronger" one
// to provide more expected results.
if ( a instanceof RemoveOperation && !( b instanceof RemoveOperation ) ) {
if ( a.type == 'remove' && b.type != 'remove' ) {
aIsStrong = true;
} else if ( !( a instanceof RemoveOperation ) && b instanceof RemoveOperation ) {
} else if ( a.type != 'remove' && b.type == 'remove' ) {
aIsStrong = false;
}

Expand Down Expand Up @@ -1050,7 +1026,7 @@ setTransformation( MoveOperation, MergeOperation, ( a, b, context ) => {
const movedRange = Range.createFromPositionAndShift( a.sourcePosition, a.howMany );

if ( b.deletionPosition.hasSameParentAs( a.sourcePosition ) && movedRange.containsPosition( b.sourcePosition ) ) {
if ( a instanceof RemoveOperation ) {
if ( a.type == 'remove' ) {
// Case 1: The element to remove got merged.
// Merge operation does support merging elements which are not siblings. So it would not be a problem
// from technical point of view. However, if the element was removed, the intention of the user
Expand Down Expand Up @@ -1767,25 +1743,12 @@ function makeMoveOperationsFromRanges( ranges, targetPosition ) {
}

function makeMoveOperation( range, targetPosition ) {
// We want to keep correct operation class.
let OperationClass;

if ( targetPosition.root.rootName == '$graveyard' ) {
OperationClass = RemoveOperation;
} else if ( range.start.root.rootName == '$graveyard' ) {
OperationClass = ReinsertOperation;
} else {
OperationClass = MoveOperation;
}

targetPosition.stickiness = 'toNone';

const result = new OperationClass(
return new MoveOperation(
range.start,
range.end.offset - range.start.offset,
targetPosition,
0 // Is corrected anyway later.
0
);

return result;
}
5 changes: 2 additions & 3 deletions src/model/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import DetachOperation from './operation/detachoperation';
import InsertOperation from './operation/insertoperation';
import MarkerOperation from './operation/markeroperation';
import MoveOperation from './operation/moveoperation';
import RemoveOperation from './operation/removeoperation';
import RenameOperation from './operation/renameoperation';
import RootAttributeOperation from './operation/rootattributeoperation';
import SplitOperation from './operation/splitoperation';
Expand Down Expand Up @@ -1330,7 +1329,7 @@ function applyMarkerOperation( writer, name, oldRange, newRange, affectsData ) {
model.applyOperation( operation );
}

// Creates `RemoveOperation` or `DetachOperation` that removes `howMany` nodes starting from `position`.
// Creates `MoveOperation` or `DetachOperation` that removes `howMany` nodes starting from `position`.
// The operation will be applied on given model instance and added to given operation instance.
//
// @private
Expand All @@ -1345,7 +1344,7 @@ function applyRemoveOperation( position, howMany, batch, model ) {
const doc = model.document;
const graveyardPosition = new Position( doc.graveyard, [ 0 ] );

operation = new RemoveOperation( position, howMany, graveyardPosition, doc.version );
operation = new MoveOperation( position, howMany, graveyardPosition, doc.version );
} else {
operation = new DetachOperation( position, howMany );
}
Expand Down
5 changes: 2 additions & 3 deletions tests/dev-utils/enableenginedebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import MoveOperation from '../../src/model/operation/moveoperation';
import NoOperation from '../../src/model/operation/nooperation';
import RenameOperation from '../../src/model/operation/renameoperation';
import RootAttributeOperation from '../../src/model/operation/rootattributeoperation';
import RemoveOperation from '../../src/model/operation/removeoperation';
import transform from '../../src/model/operation/transform';
import Model from '../../src/model/model';
import ModelDocumentFragment from '../../src/model/documentfragment';
Expand Down Expand Up @@ -532,8 +531,8 @@ describe( 'debug tools', () => {
model.applyOperation( insert );

const graveyard = modelDoc.graveyard;
const remove = new RemoveOperation( ModelPosition.createAt( modelRoot, 1 ), 2, ModelPosition.createAt( graveyard, 0 ), 1 );
model.applyOperation( remove );
const move = new MoveOperation( ModelPosition.createAt( modelRoot, 1 ), 2, ModelPosition.createAt( graveyard, 0 ), 1 );
model.applyOperation( move );
} );

log.resetHistory();
Expand Down
3 changes: 1 addition & 2 deletions tests/model/differ.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Position from '../../src/model/position';
import Range from '../../src/model/range';

import InsertOperation from '../../src/model/operation/insertoperation';
import RemoveOperation from '../../src/model/operation/removeoperation';
import MoveOperation from '../../src/model/operation/moveoperation';
import RenameOperation from '../../src/model/operation/renameoperation';
import AttributeOperation from '../../src/model/operation/attributeoperation';
Expand Down Expand Up @@ -1617,7 +1616,7 @@ describe( 'Differ', () => {

function remove( sourcePosition, howMany ) {
const targetPosition = Position.createAt( doc.graveyard, doc.graveyard.maxOffset );
const operation = new RemoveOperation( sourcePosition, howMany, targetPosition, doc.version );
const operation = new MoveOperation( sourcePosition, howMany, targetPosition, doc.version );

model.applyOperation( operation );
}
Expand Down

0 comments on commit 49d2318

Please sign in to comment.