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

Commit

Permalink
Merge pull request #1710 from ckeditor/t/1709
Browse files Browse the repository at this point in the history
Internal: Rewritten `model.Writer#wrap()` to use `insert()` and `move()` instead of own code. Closes #1709.
  • Loading branch information
Piotr Jasiun committed Mar 28, 2019
2 parents bd875c7 + 37556b8 commit c0688d1
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/model/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,22 +814,12 @@ export default class Writer {
throw new CKEditorError( 'writer-wrap-element-attached: Element to wrap with is already attached to tree model.' );
}

const version = range.root.document ? range.root.document.version : null;

// Has to be `range.start` not `range.end` for better transformations.
const insert = new InsertOperation( range.start, element, version );
this.batch.addOperation( insert );
this.model.applyOperation( insert );
this.insert( element, range.start );

const move = new MoveOperation(
range.start.getShiftedBy( 1 ),
range.end.offset - range.start.offset,
Position._createAt( element, 0 ),
version === null ? null : version + 1
);
// Shift the range-to-wrap because we just inserted an element before that range.
const shiftedRange = new Range( range.start.getShiftedBy( 1 ), range.end.getShiftedBy( 1 ) );

this.batch.addOperation( move );
this.model.applyOperation( move );
this.move( shiftedRange, Position._createAt( element, 0 ) );
}

/**
Expand Down

0 comments on commit c0688d1

Please sign in to comment.