| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- /**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
- /**
- * @module engine/model/operation/markeroperation
- */
- import Operation from './operation';
- import Range from '../range';
- /**
- * @extends module:engine/model/operation/operation~Operation
- */
- export default class MarkerOperation extends Operation {
- /**
- * @param {String} name Marker name.
- * @param {module:engine/model/range~Range} oldRange Marker range before the change.
- * @param {module:engine/model/range~Range} newRange Marker range after the change.
- * @param {module:engine/model/markercollection~MarkerCollection} markers Marker collection on which change should be executed.
- * @param {Boolean} affectsData Specifies whether the marker operation affects the data produced by the data pipeline
- * (is persisted in the editor's data).
- * @param {Number|null} baseVersion Document {@link module:engine/model/document~Document#version} on which operation
- * can be applied or `null` if the operation operates on detached (non-document) tree.
- */
- constructor( name, oldRange, newRange, markers, affectsData, baseVersion ) {
- super( baseVersion );
- /**
- * Marker name.
- *
- * @readonly
- * @member {String}
- */
- this.name = name;
- /**
- * Marker range before the change.
- *
- * @readonly
- * @member {module:engine/model/range~Range}
- */
- this.oldRange = oldRange ? oldRange.clone() : null;
- /**
- * Marker range after the change.
- *
- * @readonly
- * @member {module:engine/model/range~Range}
- */
- this.newRange = newRange ? newRange.clone() : null;
- /**
- * Specifies whether the marker operation affects the data produced by the data pipeline
- * (is persisted in the editor's data).
- *
- * @readonly
- * @member {Boolean}
- */
- this.affectsData = affectsData;
- /**
- * Marker collection on which change should be executed.
- *
- * @private
- * @member {module:engine/model/markercollection~MarkerCollection}
- */
- this._markers = markers;
- }
- /**
- * @inheritDoc
- */
- get type() {
- return 'marker';
- }
- /**
- * Creates and returns an operation that has the same parameters as this operation.
- *
- * @returns {module:engine/model/operation/markeroperation~MarkerOperation} Clone of this operation.
- */
- clone() {
- return new MarkerOperation( this.name, this.oldRange, this.newRange, this._markers, this.affectsData, this.baseVersion );
- }
- /**
- * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
- *
- * @returns {module:engine/model/operation/markeroperation~MarkerOperation}
- */
- getReversed() {
- return new MarkerOperation( this.name, this.newRange, this.oldRange, this._markers, this.affectsData, this.baseVersion + 1 );
- }
- /**
- * @inheritDoc
- */
- _execute() {
- const type = this.newRange ? '_set' : '_remove';
- this._markers[ type ]( this.name, this.newRange, true, this.affectsData );
- }
- /**
- * @inheritDoc
- */
- toJSON() {
- const json = super.toJSON();
- if ( this.oldRange ) {
- json.oldRange = this.oldRange.toJSON();
- }
- if ( this.newRange ) {
- json.newRange = this.newRange.toJSON();
- }
- delete json._markers;
- return json;
- }
- /**
- * @inheritDoc
- */
- static get className() {
- return 'MarkerOperation';
- }
- /**
- * Creates `MarkerOperation` object from deserialized object, i.e. from parsed JSON string.
- *
- * @param {Object} json Deserialized JSON object.
- * @param {module:engine/model/document~Document} document Document on which this operation will be applied.
- * @returns {module:engine/model/operation/markeroperation~MarkerOperation}
- */
- static fromJSON( json, document ) {
- return new MarkerOperation(
- json.name,
- json.oldRange ? Range.fromJSON( json.oldRange, document ) : null,
- json.newRange ? Range.fromJSON( json.newRange, document ) : null,
- document.model.markers,
- json.affectsData,
- json.baseVersion
- );
- }
- // @if CK_DEBUG_ENGINE // toString() {
- // @if CK_DEBUG_ENGINE // return `MarkerOperation( ${ this.baseVersion } ): ` +
- // @if CK_DEBUG_ENGINE // `"${ this.name }": ${ this.oldRange } -> ${ this.newRange }`;
- // @if CK_DEBUG_ENGINE // }
- }
|