Преглед на файлове

Handle collapsed selection in text with attribute.

Maciej Gołaszewski преди 6 години
родител
ревизия
457238f8c7

+ 5 - 1
packages/ckeditor5-restricted-editing/src/restricteddocumentcommand.js

@@ -38,7 +38,11 @@ export default class RestrictedDocumentCommand extends Command {
 			const ranges = model.schema.getValidRanges( selection.getRanges(), 'nonRestricted' );
 
 			if ( selection.isCollapsed ) {
-				writer.setSelectionAttribute( 'nonRestricted', true );
+				if ( valueToSet ) {
+					writer.setSelectionAttribute( 'nonRestricted', true );
+				} else {
+					writer.removeSelectionAttribute( 'nonRestricted' );
+				}
 			} else {
 				for ( const range of ranges ) {
 					if ( valueToSet ) {

+ 8 - 0
packages/ckeditor5-restricted-editing/tests/restricteddocumentcommand.js

@@ -117,6 +117,14 @@ describe( 'RestrictedDocumentCommand', () => {
 
 				expect( model.document.selection.hasAttribute( 'nonRestricted' ) ).to.be.true;
 			} );
+
+			it( 'should remove selection attribute if text has non-restricted attribute', () => {
+				setData( model, '<p>abc<$text nonRestricted="true">foo[]bar</$text>baz</p>' );
+
+				command.execute();
+
+				expect( model.document.selection.hasAttribute( 'nonRestricted' ) ).to.be.false;
+			} );
 		} );
 
 		describe( 'non-collapsed selection', () => {