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

Handle collapsed selection in text without attribute.

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

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

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

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

@@ -109,6 +109,16 @@ describe( 'RestrictedDocumentCommand', () => {
 	} );
 
 	describe( 'execute()', () => {
+		describe( 'collapsed selection', () => {
+			it( 'should set selection attribute if text without attribute', () => {
+				setData( model, '<p>abcfoo[]barbaz</p>' );
+
+				command.execute();
+
+				expect( model.document.selection.hasAttribute( 'nonRestricted' ) ).to.be.true;
+			} );
+		} );
+
 		describe( 'non-collapsed selection', () => {
 			it( 'should do nothing if the command is disabled', () => {
 				setData( model, '<p>fo[ob]ar</p>' );