Преглед на файлове

Merge pull request #20 from ckeditor/t/19

Fix: Editor element should be filled up with data once the editor is destroyed. Closes #19.
Piotrek Koszuliński преди 8 години
родител
ревизия
e76c3f350f
променени са 2 файла, в които са добавени 29 реда и са изтрити 4 реда
  1. 6 2
      packages/ckeditor5-editor-inline/src/inlineeditor.js
  2. 23 2
      packages/ckeditor5-editor-inline/tests/inlineeditor.js

+ 6 - 2
packages/ckeditor5-editor-inline/src/inlineeditor.js

@@ -11,6 +11,7 @@ import StandardEditor from '@ckeditor/ckeditor5-core/src/editor/standardeditor';
 import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
 import InlineEditorUI from './inlineeditorui';
 import InlineEditorUIView from './inlineeditoruiview';
+import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement';
 
 import '../theme/theme.scss';
 
@@ -42,10 +43,13 @@ export default class InlineEditor extends StandardEditor {
 	 * @returns {Promise}
 	 */
 	destroy() {
-		this.updateEditorElement();
+		// Cache the data, then destroy.
+		// It's safe to assume that the model->view conversion will not work after super.destroy().
+		const data = this.getData();
 
 		return this.ui.destroy()
-			.then( () => super.destroy() );
+			.then( () => super.destroy() )
+			.then( () => setDataInElement( this.element, data ) );
 	}
 
 	/**

+ 23 - 2
packages/ckeditor5-editor-inline/tests/inlineeditor.js

@@ -9,6 +9,8 @@ import InlineEditorUI from '../src/inlineeditorui';
 import InlineEditorUIView from '../src/inlineeditoruiview';
 
 import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
+import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
+import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
 
 import InlineEditor from '../src/inlineeditor';
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
@@ -168,15 +170,34 @@ describe( 'InlineEditor', () => {
 			return InlineEditor.create( editorElement, { plugins: [ Paragraph ] } )
 				.then( newEditor => {
 					editor = newEditor;
+
+					const schema = editor.document.schema;
+
+					schema.registerItem( 'heading' );
+					schema.allow( { name: 'heading', inside: '$root' } );
+					schema.allow( { name: '$text', inside: 'heading' } );
+
+					buildModelConverter().for( editor.data.modelToView )
+						.fromElement( 'heading' )
+						.toElement( 'heading' );
+
+					buildViewConverter().for( editor.data.viewToModel )
+						.fromElement( 'heading' )
+						.toElement( 'heading' );
+
+					buildModelConverter().for( editor.editing.modelToView )
+						.fromElement( 'heading' )
+						.toElement( 'heading-editing-representation' );
 				} );
 		} );
 
 		it( 'sets the data back to the editor element', () => {
-			editor.setData( '<p>foo</p>' );
+			editor.setData( '<p>a</p><heading>b</heading>' );
 
 			return editor.destroy()
 				.then( () => {
-					expect( editorElement.innerHTML ).to.equal( '<p>foo</p>' );
+					expect( editorElement.innerHTML )
+						.to.equal( '<p>a</p><heading>b</heading>' );
 				} );
 		} );
 	} );