Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Modify document selection in change block in deleteContent decorator …
Browse files Browse the repository at this point in the history
…method.
  • Loading branch information
jodator committed Dec 19, 2019
1 parent f552731 commit 8272933
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/restrictededitingmodeediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,14 @@ function restrictDeleteContent( editor ) {
// Shrink the selection to the range inside exception marker.
const allowedToDelete = marker.getRange().getIntersection( selection.getFirstRange() );

// Because the DeleteCommand uses the same selection to set selection after calling model.deleteContent() it is better to modify
// the argument selection. The only problem is when that when DocumentSelection is passed (or used internally) as it does allows
// to be modified.
// Instead we change the arguments passed to `deleteContent()` method when document selection was passed.
// Some features uses selection passed to model.deleteContent() to set the selection afterwards. For this we need to properly modify
// either the document selection using change block...
if ( selection.is( 'documentSelection' ) ) {
args[ 0 ] = editor.model.createSelection( allowedToDelete );
editor.model.change( writer => {
writer.setSelection( allowedToDelete );
} );
}
// We need to modify selection passed to deleteContent if it is an instance of selection because DeleteCommand uses passed
// selection to set selection afterwards. Since we modifying this here the selection set after the delete content will be invalid.
// ... or by modifying passed selection instance directly.
else {
selection.setTo( allowedToDelete );
}
Expand Down

0 comments on commit 8272933

Please sign in to comment.