8
0
Эх сурвалжийг харах

Modify document selection in change block in deleteContent decorator method.

Maciej Gołaszewski 6 жил өмнө
parent
commit
70ce621ad2

+ 6 - 7
packages/ckeditor5-restricted-editing/src/restrictededitingmodeediting.js

@@ -331,15 +331,14 @@ function restrictDeleteContent( editor ) {
 		// Shrink the selection to the range inside exception marker.
 		// Shrink the selection to the range inside exception marker.
 		const allowedToDelete = marker.getRange().getIntersection( selection.getFirstRange() );
 		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' ) ) {
 		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 {
 		else {
 			selection.setTo( allowedToDelete );
 			selection.setTo( allowedToDelete );
 		}
 		}