瀏覽代碼

Merge pull request #51 from ckeditor/t/40

Fixed the issue when loading enter feature after heading would break overriding the enter in heading behaviour.
Szymon Kupś 9 年之前
父節點
當前提交
5021fa1915
共有 2 個文件被更改,包括 55 次插入0 次删除
  1. 8 0
      packages/ckeditor5-heading/src/headingengine.js
  2. 47 0
      packages/ckeditor5-heading/tests/tickets/40.js

+ 8 - 0
packages/ckeditor5-heading/src/headingengine.js

@@ -63,9 +63,17 @@ export default class HeadingEngine extends Plugin {
 		// Register the heading command.
 		const command = new HeadingCommand( editor, formats );
 		editor.commands.set( 'heading', command );
+	}
 
+	/**
+	 * @inheritDoc
+	 */
+	afterInit() {
 		// If the enter command is added to the editor, alter its behavior.
 		// Enter at the end of a heading element should create a paragraph.
+
+		const editor = this.editor;
+		const command = editor.commands.get( 'heading' );
 		const enterCommand = editor.commands.get( 'enter' );
 
 		if ( enterCommand ) {

+ 47 - 0
packages/ckeditor5-heading/tests/tickets/40.js

@@ -0,0 +1,47 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import HeadingEngine from 'ckeditor5/heading/headingengine.js';
+import VirtualTestEditor from 'tests/core/_utils/virtualtesteditor.js';
+import Enter from 'ckeditor5/enter/enter.js';
+import { getData, setData } from 'ckeditor5/engine/dev-utils/model.js';
+
+describe( 'Bug ckeditor5-heading#40', () => {
+	let editor;
+
+	afterEach( () => {
+		return editor.destroy();
+	} );
+
+	it( 'enter at the end of a heading creates a paragraph, when heading was loaded before enter', () => {
+		return VirtualTestEditor.create( {
+			plugins: [ HeadingEngine, Enter ]
+		} )
+		.then( newEditor => {
+			editor = newEditor;
+
+			setData( editor.document, '<heading1>foo[]</heading1>' );
+
+			editor.execute( 'enter' );
+
+			expect( getData( editor.document ) ).to.equal( '<heading1>foo</heading1><paragraph>[]</paragraph>' );
+		} );
+	} );
+
+	it( 'enter at the end of a heading creates a paragraph, when enter was loaded before heading', () => {
+		return VirtualTestEditor.create( {
+			plugins: [ Enter, HeadingEngine ]
+		} )
+		.then( newEditor => {
+			editor = newEditor;
+
+			setData( editor.document, '<heading1>foo[]</heading1>' );
+
+			editor.execute( 'enter' );
+
+			expect( getData( editor.document ) ).to.equal( '<heading1>foo</heading1><paragraph>[]</paragraph>' );
+		} );
+	} );
+} );