Przeglądaj źródła

Fix case of typing inside exception marker.

Maciej Gołaszewski 6 lat temu
rodzic
commit
e8b3745618

+ 3 - 2
packages/ckeditor5-restricted-editing/src/restrictedediting.js

@@ -43,11 +43,12 @@ export default class RestrictedEditing extends Plugin {
 
 		editor.conversion.for( 'downcast' ).markerToHighlight( {
 			model: 'restricted-editing-exception',
-			view: {
+			// Use callback to return new object every time new marker instance is created - otherwise it will be seen as the same marker.
+			view: () => ( {
 				name: 'span',
 				classes: 'ck-restricted-editing-exception',
 				priority: -10
-			}
+			} )
 		} );
 	}
 }

+ 49 - 0
packages/ckeditor5-restricted-editing/tests/restrictedediting.js

@@ -128,4 +128,53 @@ describe( 'RestrictedEditing', () => {
 			} );
 		} );
 	} );
+
+	describe( 'editing behavior', () => {
+		let model;
+
+		beforeEach( async () => {
+			editor = await VirtualTestEditor.create( { plugins: [ Paragraph, RestrictedEditing ] } );
+			model = editor.model;
+		} );
+
+		afterEach( () => {
+			return editor.destroy();
+		} );
+
+		it( 'should keep markers in the view when editable region is edited', () => {
+			setModelData( model,
+				'<paragraph>foo bar baz</paragraph>' +
+				'<paragraph>xxx y[]yy zzz</paragraph>'
+			);
+
+			const firstParagraph = model.document.getRoot().getChild( 0 );
+			const secondParagraph = model.document.getRoot().getChild( 1 );
+
+			model.change( writer => {
+				writer.addMarker( 'restricted-editing-exception:1', {
+					range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ), writer.createPositionAt( firstParagraph, 7 ) ),
+					usingOperation: true,
+					affectsData: true
+				} );
+				writer.addMarker( 'restricted-editing-exception:2', {
+					range: writer.createRange(
+						writer.createPositionAt( secondParagraph, 4 ),
+						writer.createPositionAt( secondParagraph, 7 )
+					),
+					usingOperation: true,
+					affectsData: true
+				} );
+			} );
+
+			model.change( writer => {
+				model.insertContent( writer.createText( 'R', model.document.selection.getAttributes() ) );
+			} );
+
+			const expectedView = '<p>foo <span class="ck-restricted-editing-exception">bar</span> baz</p>' +
+				'<p>xxx <span class="ck-restricted-editing-exception">yRyy</span> zzz</p>';
+
+			expect( editor.getData() ).to.equal( expectedView );
+			expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
+		} );
+	} );
 } );