Procházet zdrojové kódy

Added "model.Writer#setTextData()" for updating the content for specified text node.

Kamil Piechaczek před 8 roky
rodič
revize
60457116b5

+ 10 - 0
packages/ckeditor5-engine/src/model/writer.js

@@ -322,6 +322,16 @@ export default class Writer {
 		}
 	}
 
+	/**
+	 * Sets the text content for the specified `textNode`.
+	 *
+	 * @param {String} value New value.
+	 * @param {module:engine/model/text~Text} textNode Text node that will be updated.
+	 */
+	setTextData( value, textNode ) {
+		textNode._data = value;
+	}
+
 	/**
 	 * Sets value of the attribute with given key on a {@link module:engine/model/item~Item model item}
 	 * or on a {@link module:engine/model/range~Range range}.

+ 16 - 0
packages/ckeditor5-engine/tests/model/writer.js

@@ -811,6 +811,16 @@ describe( 'Writer', () => {
 		} );
 	} );
 
+	describe( 'setTextData()', () => {
+		it( 'should update the content for text node', () => {
+			const textNode = createText( 'foo' );
+
+			setTextData( 'bar', textNode );
+
+			expect( textNode.data ).to.equal( 'bar' );
+		} );
+	} );
+
 	describe( 'setAttribute() / removeAttribute()', () => {
 		let root, spy;
 
@@ -2462,6 +2472,12 @@ describe( 'Writer', () => {
 		} );
 	}
 
+	function setTextData( value, textNode ) {
+		model.enqueueChange( batch, writer => {
+			writer.setTextData( value, textNode );
+		} );
+	}
+
 	function setAttribute( key, value, itemOrRange ) {
 		model.enqueueChange( batch, writer => {
 			writer.setAttribute( key, value, itemOrRange );