Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Added "model.Writer#setTextData()" for updating the content for speci…
Browse files Browse the repository at this point in the history
…fied text node.
  • Loading branch information
Kamil Piechaczek committed Mar 7, 2018
1 parent 7852ef3 commit b66c4c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/model/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
16 changes: 16 additions & 0 deletions tests/model/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit b66c4c8

Please sign in to comment.