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

Commit

Permalink
Added missing view.Document to ViewDocumentFragment.
Browse files Browse the repository at this point in the history
  • Loading branch information
pomek committed Mar 16, 2020
1 parent 99855b5 commit 6f99734
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';

import ViewDocumentFragment from '@ckeditor/ckeditor5-engine/src/view/documentfragment';
import ViewDowncastWriter from '@ckeditor/ckeditor5-engine/src/view/downcastwriter';
import ViewDocument from '@ckeditor/ckeditor5-engine/src/view/document';
import first from '@ckeditor/ckeditor5-utils/src/first';
import {
needsPlaceholder,
Expand Down Expand Up @@ -142,13 +141,14 @@ export default class Title extends Plugin {
* @returns {String} The body of the document.
*/
getBody() {
const data = this.editor.data;
const model = this.editor.model;
const root = this.editor.model.document.getRoot();
const viewWriter = new ViewDowncastWriter( new ViewDocument() );
const editor = this.editor;
const data = editor.data;
const model = editor.model;
const root = editor.model.document.getRoot();
const viewWriter = new ViewDowncastWriter( editor.editing.view.document );

const rootRange = model.createRangeIn( root );
const viewDocumentFragment = new ViewDocumentFragment();
const viewDocumentFragment = new ViewDocumentFragment( editor.editing.view.document );

// Convert the entire root to view.
data.mapper.clearBindings();
Expand All @@ -171,7 +171,7 @@ export default class Title extends Plugin {
viewWriter.remove( viewWriter.createRangeOn( viewDocumentFragment.getChild( 0 ) ) );

// view -> data
return this.editor.data.processor.toData( viewDocumentFragment );
return editor.data.processor.toData( viewDocumentFragment );
}

/**
Expand Down
61 changes: 61 additions & 0 deletions tests/title-integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* global document */

import Title from '../src/title';
import Heading from '../src/heading.js';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Enter from '@ckeditor/ckeditor5-enter/src/enter';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';

import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
import { getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';

describe( 'Title integration', () => {
let editor, model, doc, element;

beforeEach( () => {
element = document.createElement( 'div' );
document.body.appendChild( element );

return ClassicTestEditor
.create( element, {
plugins: [ Paragraph, Heading, Enter, Bold, Title ]
} )
.then( newEditor => {
editor = newEditor;
model = editor.model;
doc = model.document;
} );
} );

afterEach( () => {
element.remove();

return editor.destroy();
} );

describe( 'getBody()', () => {
// See: https://github.com/ckeditor/ckeditor5/issues/6427
it( 'does not blow up when applying basic styles', () => {
editor.setData( '<h1>Title</h1><p>Foo</p>' );

editor.model.change( writer => {
writer.setSelection( doc.getRoot().getChild( 1 ), 'on' );
} );

editor.execute( 'bold' );

expect( editor.plugins.get( Title ).getBody() ).to.equal(
'<p><strong>Foo</strong></p>'
);

expect( getModelData( model ) ).to.equal(
'<title><title-content>Title</title-content></title><paragraph>[<$text bold="true">Foo</$text>]</paragraph>'
);
} );
} );
} );

0 comments on commit 6f99734

Please sign in to comment.