Skip to content

Commit

Permalink
Merge pull request #8186 from ckeditor/i/8145
Browse files Browse the repository at this point in the history
Fix (engine): `Model#deleteContent()` should properly remove blocks when the selection is spanning multiple blocks. Closes #8145.
  • Loading branch information
jodator authored Sep 30, 2020
2 parents 0063c6e + 0b78edb commit c4b3182
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/ckeditor5-engine/src/model/utils/deletecontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions packages/ckeditor5-engine/tests/model/utils/deletecontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>',
Expand Down

0 comments on commit c4b3182

Please sign in to comment.