Sfoglia il codice sorgente

Added a flag "preventReplacingWithParagraph" to `DataController#deleteContent()` method.

Kamil Piechaczek 8 anni fa
parent
commit
14fc0c4fc4

+ 2 - 1
packages/ckeditor5-engine/src/controller/deletecontent.js

@@ -19,6 +19,7 @@ import Element from '../model/element';
  * @param {module:engine/model/batch~Batch} batch Batch to which the deltas will be added.
  * @param {Object} [options]
  * @param {Boolean} [options.leaveUnmerged=false] Whether to merge elements after removing the content of the selection.
+ * @param {Boolean} [options.preventReplacingWithParagraph=false] Whether the entire content shouldn't be replaced with the paragraph.
  *
  * For example `<h>x[x</h><p>y]y</p>` will become:
  * * `<h>x^y</h>` with the option disabled (`leaveUnmerged == false`)
@@ -34,7 +35,7 @@ export default function deleteContent( selection, batch, options = {} ) {
 
 	// 1. Replace the entire content with paragraph.
 	// See: https://github.com/ckeditor/ckeditor5-engine/issues/1012#issuecomment-315017594.
-	if ( shouldEntireContentBeReplacedWithParagraph( batch.document.schema, selection ) ) {
+	if ( !options.preventReplacingWithParagraph && shouldEntireContentBeReplacedWithParagraph( batch.document.schema, selection ) ) {
 		replaceEntireContentWithParagraph( batch, selection );
 
 		return;

+ 9 - 0
packages/ckeditor5-engine/tests/controller/deletecontent.js

@@ -749,6 +749,15 @@ describe( 'DataController', () => {
 				expect( getData( doc, { rootName: 'paragraphRoot' } ) )
 					.to.equal( 'x[]z' );
 			} );
+
+			test(
+				'but not if the flag "preventReplacingWithParagraph" is set on true',
+				'<heading1>[</heading1><paragraph>]</paragraph>',
+				'<heading1>[]</heading1>',
+				{
+					preventReplacingWithParagraph: true
+				}
+			);
 		} );
 
 		function test( title, input, output, options ) {