Răsfoiți Sursa

Added: `view.TextProxy#offsetSize` property.

Szymon Cofalik 8 ani în urmă
părinte
comite
e7cd0e9296

+ 3 - 1
packages/ckeditor5-engine/src/view/range.js

@@ -438,7 +438,9 @@ export default class Range {
 	 * @returns {module:engine/view/range~Range}
 	 */
 	static createOn( item ) {
-		return this.createFromPositionAndShift( Position.createBefore( item ), 1 );
+		const size = item.is( 'textProxy' ) ? item.offsetSize : 1;
+
+		return this.createFromPositionAndShift( Position.createBefore( item ), size );
 	}
 
 	/**

+ 7 - 0
packages/ckeditor5-engine/src/view/textproxy.js

@@ -84,6 +84,13 @@ export default class TextProxy {
 		this.offsetInText = offsetInText;
 	}
 
+	/**
+	 * @inheritDoc
+	 */
+	get offsetSize() {
+		return this.data.length;
+	}
+
 	/**
 	 * Flag indicating whether `TextProxy` instance covers only part of the original {@link module:engine/view/text~Text text node}
 	 * (`true`) or the whole text node (`false`).

+ 6 - 0
packages/ckeditor5-engine/tests/view/textproxy.js

@@ -78,6 +78,12 @@ describe( 'TextProxy', () => {
 		} );
 	} );
 
+	describe( 'offsetSize', () => {
+		it( 'should be equal to the number of characters in text proxy', () => {
+			expect( textProxy.offsetSize ).to.equal( 3 );
+		} );
+	} );
+
 	describe( 'getDocument', () => {
 		it( 'should return null if any parent has not set Document', () => {
 			expect( textProxy.document ).to.be.null;