Explorar el Código

Merge pull request #8186 from ckeditor/i/8145

Fix (engine): `Model#deleteContent()` should properly remove blocks when the selection is spanning multiple blocks. Closes #8145.
Maciej hace 5 años
padre
commit
c4b3182722

+ 2 - 2
packages/ckeditor5-engine/src/model/utils/deletecontent.js

@@ -84,8 +84,8 @@ export default function deleteContent( model, selection, options = {} ) {
 		const [ startPosition, endPosition ] = getLivePositionsForSelectedBlocks( selRange );
 
 		// 2. Remove the content if there is any.
-		if ( !selRange.start.isTouching( selRange.end ) ) {
-			writer.remove( selRange );
+		if ( !startPosition.isTouching( endPosition ) ) {
+			writer.remove( writer.createRange( startPosition, endPosition ) );
 		}
 
 		// 3. Merge elements in the right branch to the elements in the left branch.

+ 6 - 0
packages/ckeditor5-engine/tests/model/utils/deletecontent.js

@@ -249,6 +249,12 @@ describe( 'DataController utils', () => {
 				'<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>bar</paragraph><paragraph>y</paragraph>'
 			);
 
+			test(
+				'do not remove end block if selection ends at start position of it (multiple paragraphs)',
+				'<paragraph>x</paragraph><paragraph>[foo</paragraph><paragraph>a</paragraph><paragraph>]bar</paragraph>',
+				'<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>bar</paragraph>'
+			);
+
 			test(
 				'removes empty element (merges it into second element)',
 				'<paragraph>x</paragraph><paragraph>[</paragraph><paragraph>]bar</paragraph><paragraph>y</paragraph>',