8
0
فهرست منبع

Disable typing for non-collapsed selection that extends over exception marker.

Maciej Gołaszewski 6 سال پیش
والد
کامیت
babca118dc

+ 6 - 0
packages/ckeditor5-restricted-editing/src/restrictededitingediting.js

@@ -66,6 +66,12 @@ export default class RestrictedEditingEditing extends Plugin {
 		const selection = editor.model.document.selection;
 
 		this.listenTo( selection, 'change', () => {
+			if ( !selection.isCollapsed ) {
+				this._disableCommands( editor );
+
+				return;
+			}
+
 			const marker = Array.from( editor.model.markers.getMarkersAtPosition( selection.focus ) )
 				.find( marker => marker.name.startsWith( 'restricted-editing-exception:' ) );
 

+ 14 - 3
packages/ckeditor5-restricted-editing/tests/restrictededitingediting.js

@@ -272,7 +272,7 @@ describe( 'RestrictedEditingEditing', () => {
 
 		describe( 'input', () => {
 			beforeEach( () => {
-				editor.commands.add( 'bold', buildFakeCommand( editor ) );
+				editor.commands.add( 'input', buildFakeCommand( editor ) );
 			} );
 
 			it( 'should be disabled outside exception marker', () => {
@@ -280,7 +280,7 @@ describe( 'RestrictedEditingEditing', () => {
 					writer.setSelection( firstParagraph, 1 );
 				} );
 
-				expect( editor.commands.get( 'bold' ).isEnabled ).to.be.false;
+				expect( editor.commands.get( 'input' ).isEnabled ).to.be.false;
 			} );
 
 			it( 'should be enabled inside exception marker', () => {
@@ -288,7 +288,18 @@ describe( 'RestrictedEditingEditing', () => {
 					writer.setSelection( firstParagraph, 5 );
 				} );
 
-				expect( editor.commands.get( 'bold' ).isEnabled ).to.be.true;
+				expect( editor.commands.get( 'input' ).isEnabled ).to.be.true;
+			} );
+
+			it( 'should be disabled for non-collapsed selection that expands over exception marker', () => {
+				model.change( writer => {
+					writer.setSelection( writer.createRange(
+						writer.createPositionAt( firstParagraph, 0 ),
+						writer.createPositionAt( firstParagraph, 5 )
+					) );
+				} );
+
+				expect( editor.commands.get( 'input' ).isEnabled ).to.be.false;
 			} );
 		} );