|
@@ -122,6 +122,9 @@ export default class Model {
|
|
|
|
|
|
|
|
injectSelectionPostFixer( this );
|
|
injectSelectionPostFixer( this );
|
|
|
|
|
|
|
|
|
|
+ // Post-fixer which takes care of adding empty paragraph elements to the empty roots.
|
|
|
|
|
+ this.document.registerPostFixer( writer => this._autoparagraphEmptyRoots( writer ) );
|
|
|
|
|
+
|
|
|
// @if CK_DEBUG_ENGINE // this.on( 'applyOperation', () => {
|
|
// @if CK_DEBUG_ENGINE // this.on( 'applyOperation', () => {
|
|
|
// @if CK_DEBUG_ENGINE // dumpTrees( this.document, this.document.version );
|
|
// @if CK_DEBUG_ENGINE // dumpTrees( this.document, this.document.version );
|
|
|
// @if CK_DEBUG_ENGINE // }, { priority: 'lowest' } );
|
|
// @if CK_DEBUG_ENGINE // }, { priority: 'lowest' } );
|
|
@@ -806,6 +809,31 @@ export default class Model {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * Fixes all empty roots.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @protected
|
|
|
|
|
+ * @returns {Boolean} `true` if any change has been applied, `false` otherwise.
|
|
|
|
|
+ */
|
|
|
|
|
+ _autoparagraphEmptyRoots( writer ) {
|
|
|
|
|
+ const { schema, document } = writer.model;
|
|
|
|
|
+
|
|
|
|
|
+ for ( const rootName of document.getRootNames() ) {
|
|
|
|
|
+ const root = document.getRoot( rootName );
|
|
|
|
|
+
|
|
|
|
|
+ if ( root.isEmpty && !schema.checkChild( root, '$text' ) ) {
|
|
|
|
|
+ // If paragraph element is allowed in the root, create paragraph element.
|
|
|
|
|
+ if ( schema.checkChild( root, 'paragraph' ) ) {
|
|
|
|
|
+ writer.insertElement( 'paragraph', root );
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* Common part of {@link module:engine/model/model~Model#change} and {@link module:engine/model/model~Model#enqueueChange}
|
|
* Common part of {@link module:engine/model/model~Model#change} and {@link module:engine/model/model~Model#enqueueChange}
|
|
|
* which calls callbacks and returns array of values returned by these callbacks.
|
|
* which calls callbacks and returns array of values returned by these callbacks.
|
|
|
*
|
|
*
|