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

Commit fe7d27b

Browse files
authored
Merge pull request #20 from ckeditor/t/19
Fix: Editor element should be filled up with data once the editor is destroyed. Closes #19.
2 parents dac7551 + 7acda76 commit fe7d27b

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/inlineeditor.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import StandardEditor from '@ckeditor/ckeditor5-core/src/editor/standardeditor';
1111
import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
1212
import InlineEditorUI from './inlineeditorui';
1313
import InlineEditorUIView from './inlineeditoruiview';
14+
import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement';
1415

1516
import '../theme/theme.scss';
1617

@@ -42,10 +43,13 @@ export default class InlineEditor extends StandardEditor {
4243
* @returns {Promise}
4344
*/
4445
destroy() {
45-
this.updateEditorElement();
46+
// Cache the data, then destroy.
47+
// It's safe to assume that the model->view conversion will not work after super.destroy().
48+
const data = this.getData();
4649

4750
return this.ui.destroy()
48-
.then( () => super.destroy() );
51+
.then( () => super.destroy() )
52+
.then( () => setDataInElement( this.element, data ) );
4953
}
5054

5155
/**

tests/inlineeditor.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import InlineEditorUI from '../src/inlineeditorui';
99
import InlineEditorUIView from '../src/inlineeditoruiview';
1010

1111
import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
12+
import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
13+
import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
1214

1315
import InlineEditor from '../src/inlineeditor';
1416
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
@@ -168,15 +170,34 @@ describe( 'InlineEditor', () => {
168170
return InlineEditor.create( editorElement, { plugins: [ Paragraph ] } )
169171
.then( newEditor => {
170172
editor = newEditor;
173+
174+
const schema = editor.document.schema;
175+
176+
schema.registerItem( 'heading' );
177+
schema.allow( { name: 'heading', inside: '$root' } );
178+
schema.allow( { name: '$text', inside: 'heading' } );
179+
180+
buildModelConverter().for( editor.data.modelToView )
181+
.fromElement( 'heading' )
182+
.toElement( 'heading' );
183+
184+
buildViewConverter().for( editor.data.viewToModel )
185+
.fromElement( 'heading' )
186+
.toElement( 'heading' );
187+
188+
buildModelConverter().for( editor.editing.modelToView )
189+
.fromElement( 'heading' )
190+
.toElement( 'heading-editing-representation' );
171191
} );
172192
} );
173193

174194
it( 'sets the data back to the editor element', () => {
175-
editor.setData( '<p>foo</p>' );
195+
editor.setData( '<p>a</p><heading>b</heading>' );
176196

177197
return editor.destroy()
178198
.then( () => {
179-
expect( editorElement.innerHTML ).to.equal( '<p>foo</p>' );
199+
expect( editorElement.innerHTML )
200+
.to.equal( '<p>a</p><heading>b</heading>' );
180201
} );
181202
} );
182203
} );

0 commit comments

Comments
 (0)