8
0
فهرست منبع

Added possibility to create position before and after TextProxy.

Oskar Wrobel 9 سال پیش
والد
کامیت
a9db2a8f8d
1فایلهای تغییر یافته به همراه13 افزوده شده و 2 حذف شده
  1. 13 2
      packages/ckeditor5-engine/src/view/position.js

+ 13 - 2
packages/ckeditor5-engine/src/view/position.js

@@ -6,6 +6,7 @@
 'use strict';
 
 import Text from './text.js';
+import TextProxy from './textproxy.js';
 
 import compareArrays from '../../utils/comparearrays.js';
 import CKEditorError from '../../utils/ckeditorerror.js';
@@ -189,7 +190,7 @@ export default class Position {
 	/**
 	 * Creates a new position after the given node.
 	 *
-	 * @param {engine.view.Node} node Node after which the position should be located.
+	 * @param {engine.view.Node|engine.view.TextProxy} node Node after which the position should be located.
 	 * @returns {engine.view.Position}
 	 */
 	static createAfter( node ) {
@@ -203,13 +204,18 @@ export default class Position {
 			throw new CKEditorError( 'position-after-root: You can not make position after root.', { root: node } );
 		}
 
+		// {@link engine.view.TextProxy} is not a instance of {@link engine.view.Node} so we need do handle it in specific way.
+		if ( node instanceof TextProxy ) {
+			return new Position( node._textNodeParent, node._index + 1 );
+		}
+
 		return new Position( node.parent, node.getIndex() + 1 );
 	}
 
 	/**
 	 * Creates a new position before the given node.
 	 *
-	 * @param {engine.view.node} node Node before which the position should be located.
+	 * @param {engine.view.Node|engine.view.TextProxy} node Node before which the position should be located.
 	 * @returns {engine.view.Position}
 	 */
 	static createBefore( node ) {
@@ -223,6 +229,11 @@ export default class Position {
 			throw new CKEditorError( 'position-before-root: You can not make position before root.', { root: node } );
 		}
 
+		// {@link engine.view.TextProxy} is not a instance of {@link engine.view.Node} so we need do handle it in specific way.
+		if ( node instanceof TextProxy ) {
+			return new Position( node._textNodeParent, node._index );
+		}
+
 		return new Position( node.parent, node.getIndex() );
 	}