Parcourir la source

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

Kamil Piechaczek il y a 7 ans
Parent
commit
2bad67acbc

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

@@ -226,6 +226,16 @@ export default class Writer {
 	}
 
 	/**
+	 * Sets the text content for the specified `textNode`.
+	 *
+	 * @param {String} value New value.
+	 * @param {module:engine/view/text~Text} textNode Text node that will be updated.
+	 */
+	setTextData( value, textNode ) {
+		textNode._data = value;
+	}
+
+	/**
 	 * Adds or overwrite element's attribute with a specified key and value.
 	 *
 	 *		writer.setAttribute( 'href', 'http://ckeditor.com', linkElement );

+ 10 - 0
packages/ckeditor5-engine/tests/view/writer/writer.js

@@ -128,6 +128,16 @@ describe( 'Writer', () => {
 		} );
 	} );
 
+	describe( 'setTextData()', () => {
+		it( 'should update the content for text node', () => {
+			const textNode = writer.createText( 'foo' );
+
+			writer.setTextData( 'bar', textNode );
+
+			expect( textNode.data ).to.equal( 'bar' );
+		} );
+	} );
+
 	describe( 'setAttribute()', () => {
 		it( 'should set attribute on given element', () => {
 			const element = writer.createAttributeElement( 'span' );