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

Commit

Permalink
Internal: Sanitize InsertOperation#position#stickiness.
Browse files Browse the repository at this point in the history
  • Loading branch information
scofalik committed Sep 6, 2018
1 parent 5c0a34d commit 7466170
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/model/operation/insertoperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class InsertOperation extends Operation {
* @member {module:engine/model/position~Position} module:engine/model/operation/insertoperation~InsertOperation#position
*/
this.position = Position.createFromPosition( position );
this.position.stickiness = 'toNone';

/**
* List of nodes to insert.
Expand Down
1 change: 1 addition & 0 deletions src/model/operation/moveoperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class MoveOperation extends Operation {
* @member {module:engine/model/position~Position} module:engine/model/operation/moveoperation~MoveOperation#sourcePosition
*/
this.sourcePosition = Position.createFromPosition( sourcePosition );
// `'toNext'` because `sourcePosition` is a bit like a start of the moved range.
this.sourcePosition.stickiness = 'toNext';

/**
Expand Down
1 change: 1 addition & 0 deletions src/model/operation/wrapoperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class WrapOperation extends Operation {
* @member {module:engine/model/position~Position} module:engine/model/operation/wrapoperation~WrapOperation#position
*/
this.position = Position.createFromPosition( position );
// `'toNext'` because `position` is a bit like a start of the wrapped range.
this.position.stickiness = 'toNext';

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/model/operation/insertoperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ describe( 'InsertOperation', () => {
expect( op.type ).to.equal( 'insert' );
} );

it( 'should have proper position stickiness', () => {
const pos = new Position( root, [ 0 ] );
pos.stickiness = 'toNext';

const op = new InsertOperation(
new Position( root, [ 0 ] ),
new Text( 'x' ),
doc.version
);

expect( op.position.stickiness ).to.equal( 'toNone' );
} );

it( 'should insert text node', () => {
model.applyOperation(
new InsertOperation(
Expand Down

0 comments on commit 7466170

Please sign in to comment.