From 4b637fd09bcf5f0e5cff89c04c66b949d7bd3a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Mon, 13 Feb 2017 14:58:31 +0100 Subject: [PATCH] Fixed issue when setData() didn't work with custom roots. --- src/dev-utils/model.js | 3 ++- tests/controller/deletecontent.js | 4 ++-- tests/dev-utils/model.js | 12 ++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/dev-utils/model.js b/src/dev-utils/model.js index 3c403207e..045ad7fd4 100644 --- a/src/dev-utils/model.js +++ b/src/dev-utils/model.js @@ -100,7 +100,8 @@ export function setData( document, data, options = {} ) { // Parse data string to model. const parsedResult = setData._parse( data, document.schema, { lastRangeBackward: options.lastRangeBackward, - selectionAttributes: options.selectionAttributes + selectionAttributes: options.selectionAttributes, + context: [ modelRoot.name ] } ); // Retrieve DocumentFragment and Selection from parsed model. diff --git a/tests/controller/deletecontent.js b/tests/controller/deletecontent.js index 546c44902..c9bcc2373 100644 --- a/tests/controller/deletecontent.js +++ b/tests/controller/deletecontent.js @@ -311,14 +311,14 @@ describe( 'DataController', () => { it( 'deletes two inline elements', () => { setData( doc, - 'x[]z', + 'x[]z', { rootName: 'paragraphRoot' } ); deleteContent( doc.selection, doc.batch() ); expect( getData( doc, { rootName: 'paragraphRoot' } ) ) - .to.equal( 'x[]z' ); + .to.equal( 'x[]z' ); } ); it( 'creates a paragraph when text is not allowed (paragraph selected)', () => { diff --git a/tests/dev-utils/model.js b/tests/dev-utils/model.js index c81b00af2..7e0179750 100644 --- a/tests/dev-utils/model.js +++ b/tests/dev-utils/model.js @@ -157,6 +157,18 @@ describe( 'model test utils', () => { expect( document.selection.getAttribute( 'foo' ) ).to.equal( 'bar' ); } ); + // #815. + it( 'should work in a special root', () => { + const document = new Document(); + + document.schema.registerItem( 'textOnly' ); + document.schema.allow( { name: '$text', inside: 'textOnly' } ); + document.createRoot( 'textOnly', 'textOnly' ); + + setData( document, 'a[b]c', { rootName: 'textOnly' } ); + expect( getData( document, { rootName: 'textOnly' } ) ).to.equal( 'a[b]c' ); + } ); + function test( data, expected ) { expected = expected || data;