|
@@ -5,7 +5,7 @@
|
|
|
|
|
|
|
|
'use strict';
|
|
'use strict';
|
|
|
|
|
|
|
|
-CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootElement, utils, CKEditorError ) => {
|
|
|
|
|
|
|
+CKEDITOR.define( [ 'treemodel/rootelement', 'utils', 'ckeditorerror' ], ( RootElement, utils, CKEditorError ) => {
|
|
|
const SAME = 0;
|
|
const SAME = 0;
|
|
|
const AFTER = 1;
|
|
const AFTER = 1;
|
|
|
const BEFORE = 2;
|
|
const BEFORE = 2;
|
|
@@ -15,13 +15,13 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
* Position in the tree. Position is always located before or after a node.
|
|
* Position in the tree. Position is always located before or after a node.
|
|
|
* See {@link #path} property for more information.
|
|
* See {@link #path} property for more information.
|
|
|
*
|
|
*
|
|
|
- * @class document.Position
|
|
|
|
|
|
|
+ * @class treeModel.Position
|
|
|
*/
|
|
*/
|
|
|
class Position {
|
|
class Position {
|
|
|
/**
|
|
/**
|
|
|
* Creates a position.
|
|
* Creates a position.
|
|
|
*
|
|
*
|
|
|
- * @param {document.RootElement} root Root element for the path. Note that this element can not have a parent.
|
|
|
|
|
|
|
+ * @param {treeModel.RootElement} root Root element for the path. Note that this element can not have a parent.
|
|
|
* @param {Array.<Number>} path Position path. Must contain at least one item. See {@link #path} property for more information.
|
|
* @param {Array.<Number>} path Position path. Must contain at least one item. See {@link #path} property for more information.
|
|
|
* @constructor
|
|
* @constructor
|
|
|
*/
|
|
*/
|
|
@@ -39,7 +39,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
/**
|
|
/**
|
|
|
* Root element for the path. Note that this element can not have a parent.
|
|
* Root element for the path. Note that this element can not have a parent.
|
|
|
*
|
|
*
|
|
|
- * @type {document.RootElement}
|
|
|
|
|
|
|
+ * @type {treeModel.RootElement}
|
|
|
*/
|
|
*/
|
|
|
this.root = root;
|
|
this.root = root;
|
|
|
|
|
|
|
@@ -77,7 +77,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
* Node directly after the position.
|
|
* Node directly after the position.
|
|
|
*
|
|
*
|
|
|
* @readonly
|
|
* @readonly
|
|
|
- * @property {document.Node}
|
|
|
|
|
|
|
+ * @property {treeModel.Node}
|
|
|
*/
|
|
*/
|
|
|
get nodeAfter() {
|
|
get nodeAfter() {
|
|
|
return this.parent.getChild( this.offset ) || null;
|
|
return this.parent.getChild( this.offset ) || null;
|
|
@@ -87,7 +87,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
* Node directly before the position.
|
|
* Node directly before the position.
|
|
|
*
|
|
*
|
|
|
* @readonly
|
|
* @readonly
|
|
|
- * @type {document.Node}
|
|
|
|
|
|
|
+ * @type {treeModel.Node}
|
|
|
*/
|
|
*/
|
|
|
get nodeBefore() {
|
|
get nodeBefore() {
|
|
|
return this.parent.getChild( this.offset - 1 ) || null;
|
|
return this.parent.getChild( this.offset - 1 ) || null;
|
|
@@ -114,7 +114,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
* Parent element of the position. The position is located at {@link #offset} in this element.
|
|
* Parent element of the position. The position is located at {@link #offset} in this element.
|
|
|
*
|
|
*
|
|
|
* @readonly
|
|
* @readonly
|
|
|
- * @property {document.Element} parent
|
|
|
|
|
|
|
+ * @property {treeModel.Element} parent
|
|
|
*/
|
|
*/
|
|
|
get parent() {
|
|
get parent() {
|
|
|
let parent = this.root;
|
|
let parent = this.root;
|
|
@@ -129,10 +129,10 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Creates and returns a new instance of {@link document.Position}
|
|
|
|
|
- * which is equal to this {@link document.Position position}.
|
|
|
|
|
|
|
+ * Creates and returns a new instance of {@link treeModel.Position}
|
|
|
|
|
+ * which is equal to this {@link treeModel.Position position}.
|
|
|
*
|
|
*
|
|
|
- * @returns {document.Position} Cloned {@link document.Position position}.
|
|
|
|
|
|
|
+ * @returns {treeModel.Position} Cloned {@link treeModel.Position position}.
|
|
|
*/
|
|
*/
|
|
|
clone() {
|
|
clone() {
|
|
|
return new Position( this.root, this.path.slice() );
|
|
return new Position( this.root, this.path.slice() );
|
|
@@ -141,7 +141,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
/**
|
|
/**
|
|
|
* Checks whether this position is before or after given position.
|
|
* Checks whether this position is before or after given position.
|
|
|
*
|
|
*
|
|
|
- * @param {document.Position} otherPosition Position to compare with.
|
|
|
|
|
|
|
+ * @param {treeModel.Position} otherPosition Position to compare with.
|
|
|
* @returns {Number} A flag indicating whether this position is {@link #BEFORE} or
|
|
* @returns {Number} A flag indicating whether this position is {@link #BEFORE} or
|
|
|
* {@link #AFTER} or {@link #SAME} as given position. If positions are in different roots,
|
|
* {@link #AFTER} or {@link #SAME} as given position. If positions are in different roots,
|
|
|
* {@link #DIFFERENT} flag is returned.
|
|
* {@link #DIFFERENT} flag is returned.
|
|
@@ -173,7 +173,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Returns the path to the parent, which is the {@link document.Position#path} without the last element.
|
|
|
|
|
|
|
+ * Returns the path to the parent, which is the {@link treeModel.Position#path} without the last element.
|
|
|
*
|
|
*
|
|
|
* This method returns the parent path even if the parent does not exists.
|
|
* This method returns the parent path even if the parent does not exists.
|
|
|
*
|
|
*
|
|
@@ -187,9 +187,9 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
* Returns this position after being updated by removing `howMany` nodes starting from `deletePosition`.
|
|
* Returns this position after being updated by removing `howMany` nodes starting from `deletePosition`.
|
|
|
* It may happen that this position is in a removed node. If that is the case, `null` is returned instead.
|
|
* It may happen that this position is in a removed node. If that is the case, `null` is returned instead.
|
|
|
*
|
|
*
|
|
|
- * @param {document.Position} deletePosition Position before the first removed node.
|
|
|
|
|
|
|
+ * @param {treeModel.Position} deletePosition Position before the first removed node.
|
|
|
* @param {Number} howMany How many nodes are removed.
|
|
* @param {Number} howMany How many nodes are removed.
|
|
|
- * @returns {document.Position|null} Transformed position or `null`.
|
|
|
|
|
|
|
+ * @returns {treeModel.Position|null} Transformed position or `null`.
|
|
|
*/
|
|
*/
|
|
|
getTransformedByDeletion( deletePosition, howMany ) {
|
|
getTransformedByDeletion( deletePosition, howMany ) {
|
|
|
let transformed = this.clone();
|
|
let transformed = this.clone();
|
|
@@ -233,12 +233,12 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
/**
|
|
/**
|
|
|
* Returns this position after being updated by inserting `howMany` nodes at `insertPosition`.
|
|
* Returns this position after being updated by inserting `howMany` nodes at `insertPosition`.
|
|
|
*
|
|
*
|
|
|
- * @param {document.Position} insertPosition Position where nodes are inserted.
|
|
|
|
|
|
|
+ * @param {treeModel.Position} insertPosition Position where nodes are inserted.
|
|
|
* @param {Number} howMany How many nodes are inserted.
|
|
* @param {Number} howMany How many nodes are inserted.
|
|
|
* @param {Boolean} insertBefore Flag indicating whether nodes are inserted before or after `insertPosition`.
|
|
* @param {Boolean} insertBefore Flag indicating whether nodes are inserted before or after `insertPosition`.
|
|
|
* This is important only when `insertPosition` and this position are same. If that is the case and the flag is
|
|
* This is important only when `insertPosition` and this position are same. If that is the case and the flag is
|
|
|
* set to `true`, this position will get transformed. If the flag is set to `false`, it won't.
|
|
* set to `true`, this position will get transformed. If the flag is set to `false`, it won't.
|
|
|
- * @returns {document.Position} Transformed position.
|
|
|
|
|
|
|
+ * @returns {treeModel.Position} Transformed position.
|
|
|
*/
|
|
*/
|
|
|
getTransformedByInsertion( insertPosition, howMany, insertBefore ) {
|
|
getTransformedByInsertion( insertPosition, howMany, insertBefore ) {
|
|
|
let transformed = this.clone();
|
|
let transformed = this.clone();
|
|
@@ -272,13 +272,13 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
/**
|
|
/**
|
|
|
* Returns this position after being updated by moving `howMany` attributes from `sourcePosition` to `targetPosition`.
|
|
* Returns this position after being updated by moving `howMany` attributes from `sourcePosition` to `targetPosition`.
|
|
|
*
|
|
*
|
|
|
- * @param {document.Position} sourcePosition Position before the first element to move.
|
|
|
|
|
- * @param {document.Position} targetPosition Position where moved elements will be inserted.
|
|
|
|
|
|
|
+ * @param {treeModel.Position} sourcePosition Position before the first element to move.
|
|
|
|
|
+ * @param {treeModel.Position} targetPosition Position where moved elements will be inserted.
|
|
|
* @param {Number} howMany How many consecutive nodes to move, starting from `sourcePosition`.
|
|
* @param {Number} howMany How many consecutive nodes to move, starting from `sourcePosition`.
|
|
|
* @param {Boolean} insertBefore Flag indicating whether moved nodes are pasted before or after `insertPosition`.
|
|
* @param {Boolean} insertBefore Flag indicating whether moved nodes are pasted before or after `insertPosition`.
|
|
|
* This is important only when `targetPosition` and this position are same. If that is the case and the flag is
|
|
* This is important only when `targetPosition` and this position are same. If that is the case and the flag is
|
|
|
* set to `true`, this position will get transformed by range insertion. If the flag is set to `false`, it won't.
|
|
* set to `true`, this position will get transformed by range insertion. If the flag is set to `false`, it won't.
|
|
|
- * @returns {document.Position} Transformed position.
|
|
|
|
|
|
|
+ * @returns {treeModel.Position} Transformed position.
|
|
|
*/
|
|
*/
|
|
|
getTransformedByMove( sourcePosition, targetPosition, howMany, insertBefore ) {
|
|
getTransformedByMove( sourcePosition, targetPosition, howMany, insertBefore ) {
|
|
|
// Moving a range removes nodes from their original position. We acknowledge this by proper transformation.
|
|
// Moving a range removes nodes from their original position. We acknowledge this by proper transformation.
|
|
@@ -300,9 +300,9 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
/**
|
|
/**
|
|
|
* Checks whether this position is after given position.
|
|
* Checks whether this position is after given position.
|
|
|
*
|
|
*
|
|
|
- * **Note:** see {document.Position#isBefore}.
|
|
|
|
|
|
|
+ * **Note:** see {treeModel.Position#isBefore}.
|
|
|
*
|
|
*
|
|
|
- * @param {document.Position} otherPosition Position to compare with.
|
|
|
|
|
|
|
+ * @param {treeModel.Position} otherPosition Position to compare with.
|
|
|
* @returns {Boolean} True if this position is after given position.
|
|
* @returns {Boolean} True if this position is after given position.
|
|
|
*/
|
|
*/
|
|
|
isAfter( otherPosition ) {
|
|
isAfter( otherPosition ) {
|
|
@@ -337,7 +337,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
* // do A.
|
|
* // do A.
|
|
|
* }
|
|
* }
|
|
|
*
|
|
*
|
|
|
- * @param {document.Position} otherPosition Position to compare with.
|
|
|
|
|
|
|
+ * @param {treeModel.Position} otherPosition Position to compare with.
|
|
|
* @returns {Boolean} True if this position is before given position.
|
|
* @returns {Boolean} True if this position is before given position.
|
|
|
*/
|
|
*/
|
|
|
isBefore( otherPosition ) {
|
|
isBefore( otherPosition ) {
|
|
@@ -347,7 +347,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
/**
|
|
/**
|
|
|
* Checks whether this position equals given position.
|
|
* Checks whether this position equals given position.
|
|
|
*
|
|
*
|
|
|
- * @param {document.Position} otherPosition Position to compare with.
|
|
|
|
|
|
|
+ * @param {treeModel.Position} otherPosition Position to compare with.
|
|
|
* @returns {Boolean} True if positions are same.
|
|
* @returns {Boolean} True if positions are same.
|
|
|
*/
|
|
*/
|
|
|
isEqual( otherPosition ) {
|
|
isEqual( otherPosition ) {
|
|
@@ -357,8 +357,8 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
/**
|
|
/**
|
|
|
* Creates a new position after given node.
|
|
* Creates a new position after given node.
|
|
|
*
|
|
*
|
|
|
- * @param {document.Node} node Node the position should be directly after.
|
|
|
|
|
- * @returns {document.Position}
|
|
|
|
|
|
|
+ * @param {treeModel.Node} node Node the position should be directly after.
|
|
|
|
|
+ * @returns {treeModel.Position}
|
|
|
*/
|
|
*/
|
|
|
static createAfter( node ) {
|
|
static createAfter( node ) {
|
|
|
if ( !node.parent ) {
|
|
if ( !node.parent ) {
|
|
@@ -366,7 +366,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
* You can not make position after root.
|
|
* You can not make position after root.
|
|
|
*
|
|
*
|
|
|
* @error position-after-root
|
|
* @error position-after-root
|
|
|
- * @param {document.Node} root
|
|
|
|
|
|
|
+ * @param {treeModel.Node} root
|
|
|
*/
|
|
*/
|
|
|
throw new CKEditorError( 'position-after-root: You can not make position after root.', { root: node } );
|
|
throw new CKEditorError( 'position-after-root: You can not make position after root.', { root: node } );
|
|
|
}
|
|
}
|
|
@@ -377,8 +377,8 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
/**
|
|
/**
|
|
|
* Creates a new position before the given node.
|
|
* Creates a new position before the given node.
|
|
|
*
|
|
*
|
|
|
- * @param {document.node} node Node the position should be directly before.
|
|
|
|
|
- * @returns {document.Position}
|
|
|
|
|
|
|
+ * @param {treeModel.node} node Node the position should be directly before.
|
|
|
|
|
+ * @returns {treeModel.Position}
|
|
|
*/
|
|
*/
|
|
|
static createBefore( node ) {
|
|
static createBefore( node ) {
|
|
|
if ( !node.parent ) {
|
|
if ( !node.parent ) {
|
|
@@ -386,7 +386,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
* You can not make position before root.
|
|
* You can not make position before root.
|
|
|
*
|
|
*
|
|
|
* @error position-before-root
|
|
* @error position-before-root
|
|
|
- * @param {document.Node} root
|
|
|
|
|
|
|
+ * @param {treeModel.Node} root
|
|
|
*/
|
|
*/
|
|
|
throw new CKEditorError( 'position-before-root: You can not make position before root.', { root: node } );
|
|
throw new CKEditorError( 'position-before-root: You can not make position before root.', { root: node } );
|
|
|
}
|
|
}
|
|
@@ -397,9 +397,9 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
/**
|
|
/**
|
|
|
* Creates a new position from the parent element and the offset in that element.
|
|
* Creates a new position from the parent element and the offset in that element.
|
|
|
*
|
|
*
|
|
|
- * @param {document.Element} parent Position parent element.
|
|
|
|
|
|
|
+ * @param {treeModel.Element} parent Position parent element.
|
|
|
* @param {Number} offset Position offset.
|
|
* @param {Number} offset Position offset.
|
|
|
- * @returns {document.Position}
|
|
|
|
|
|
|
+ * @returns {treeModel.Position}
|
|
|
*/
|
|
*/
|
|
|
static createFromParentAndOffset( parent, offset ) {
|
|
static createFromParentAndOffset( parent, offset ) {
|
|
|
const path = parent.getPath();
|
|
const path = parent.getPath();
|
|
@@ -435,9 +435,9 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
|
|
|
* Finally, the transformed position will point to `[ 1, 1, 4, 1 ]`.
|
|
* Finally, the transformed position will point to `[ 1, 1, 4, 1 ]`.
|
|
|
*
|
|
*
|
|
|
* @protected
|
|
* @protected
|
|
|
- * @param {document.Position} source Beginning of the moved range.
|
|
|
|
|
- * @param {document.Position} target Position where the range is moved.
|
|
|
|
|
- * @returns {document.Position} Combined position.
|
|
|
|
|
|
|
+ * @param {treeModel.Position} source Beginning of the moved range.
|
|
|
|
|
+ * @param {treeModel.Position} target Position where the range is moved.
|
|
|
|
|
+ * @returns {treeModel.Position} Combined position.
|
|
|
*/
|
|
*/
|
|
|
_getCombined( source, target ) {
|
|
_getCombined( source, target ) {
|
|
|
const i = source.path.length - 1;
|
|
const i = source.path.length - 1;
|