8
0
Просмотр исходного кода

Fix delete/forwardDelete commands toggling on marker boundaries.

Maciej Gołaszewski 6 лет назад
Родитель
Сommit
df4fda813a

+ 2 - 2
packages/ckeditor5-restricted-editing/src/restrictededitingmodeediting.js

@@ -187,10 +187,10 @@ export default class RestrictedEditingModeEditing extends Plugin {
 
 		const marker = getMarkerAtPosition( editor, selection.focus );
 
+		this._disableCommands();
+
 		if ( isSelectionInMarker( selection, marker ) ) {
 			this._enableCommands( marker );
-		} else {
-			this._disableCommands();
 		}
 	}
 

+ 28 - 0
packages/ckeditor5-restricted-editing/tests/restrictededitingmodeediting-commands.js

@@ -268,6 +268,20 @@ describe( 'RestrictedEditingEditing - commands', () => {
 					expect( editor.commands.get( 'delete' ).isEnabled ).to.be.false;
 				} );
 
+				it( 'should be disabled when caret moves to start boundary and it was enabled previously', () => {
+					model.change( writer => {
+						writer.setSelection( firstParagraph, 5 );
+					} );
+
+					expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;
+
+					model.change( writer => {
+						writer.setSelection( firstParagraph, 4 );
+					} );
+
+					expect( editor.commands.get( 'delete' ).isEnabled ).to.be.false;
+				} );
+
 				it( 'should be enabled when caret is inside exception marker (end boundary)', () => {
 					model.change( writer => {
 						writer.setSelection( firstParagraph, 7 );
@@ -373,6 +387,20 @@ describe( 'RestrictedEditingEditing - commands', () => {
 					expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.false;
 				} );
 
+				it( 'should be disabled when caret moves to end boundary and it was enabled previously', () => {
+					model.change( writer => {
+						writer.setSelection( firstParagraph, 5 );
+					} );
+
+					expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;
+
+					model.change( writer => {
+						writer.setSelection( firstParagraph, 7 );
+					} );
+
+					expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.false;
+				} );
+
 				it( 'should be disabled for non-collapsed selection that expands over exception marker', () => {
 					model.change( writer => {
 						writer.setSelection( writer.createRange(