Преглед изворни кода

Fix: Improved navigation across exceptions in some boundary cases.

Aleksander Nowodzinski пре 6 година
родитељ
комит
90700efcdf

+ 6 - 1
packages/ckeditor5-restricted-editing/src/restrictededitingnavigationcommand.js

@@ -80,7 +80,12 @@ function getNearestExceptionPosition( model, direction ) {
 	for ( const marker of model.markers.getMarkersGroup( 'restricted-editing-exception' ) ) {
 		const markerRange = marker.getRange();
 		const markerRangeStart = markerRange.start;
-		const isMarkerRangeTouching = selectionPosition.isTouching( markerRange.start ) || selectionPosition.isTouching( markerRange.end );
+
+		// Checking parent because there two positions <paragraph>foo^</paragraph><paragraph>^bar</paragraph>
+		// are touching but they will represent different markers.
+		const isMarkerRangeTouching =
+			selectionPosition.isTouching( markerRange.start ) && selectionPosition.hasSameParentAs( markerRange.start ) ||
+			selectionPosition.isTouching( markerRange.end ) && selectionPosition.hasSameParentAs( markerRange.end );
 
 		// <paragraph>foo <marker≥b[]ar</marker> baz</paragraph>
 		// <paragraph>foo <marker≥b[ar</marker> ba]z</paragraph>

+ 56 - 0
packages/ckeditor5-restricted-editing/tests/restrictededitingnavigationcommand.js

@@ -208,6 +208,34 @@ describe( 'RestrictedEditingNavigationCommand', () => {
 					expect( getModelData( model ) ).to.equal( '<paragraph>foo bar []baz</paragraph>' );
 				} );
 
+				it( 'should move to the next marker when at the end of adjacent one', () => {
+					setModelData( model, '<paragraph>foo[]</paragraph><paragraph>bar</paragraph>' );
+
+					const fiirstParagraph = model.document.getRoot().getChild( 0 );
+					const secondParagraph = model.document.getRoot().getChild( 1 );
+
+					// <paragraph><marker≥foo</marker>[]</paragraph><paragraph>bar</paragraph>
+					model.change( writer => {
+						writer.addMarker( 'restricted-editing-exception:1', {
+							range: writer.createRangeIn( fiirstParagraph ),
+							usingOperation: true,
+							affectsData: true
+						} );
+					} );
+
+					// <paragraph><marker≥foo</marker>[]</paragraph><paragraph><marker≥bar</marker></paragraph>
+					model.change( writer => {
+						writer.addMarker( 'restricted-editing-exception:2', {
+							range: writer.createRangeIn( secondParagraph ),
+							usingOperation: true,
+							affectsData: true
+						} );
+					} );
+
+					forwardCommand.execute();
+					expect( getModelData( model ) ).to.equal( '<paragraph>foo</paragraph><paragraph>[]bar</paragraph>' );
+				} );
+
 				it( 'should move to the closest marker when created in a reverse order', () => {
 					setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
 
@@ -472,6 +500,34 @@ describe( 'RestrictedEditingNavigationCommand', () => {
 					expect( getModelData( model ) ).to.equal( '<paragraph>foo []bar baz</paragraph>' );
 				} );
 
+				it( 'should move to the previous marker when at the beginning of adjacent one', () => {
+					setModelData( model, '<paragraph>foo</paragraph><paragraph>[]bar</paragraph>' );
+
+					const fiirstParagraph = model.document.getRoot().getChild( 0 );
+					const secondParagraph = model.document.getRoot().getChild( 1 );
+
+					// <paragraph><marker≥foo</marker></paragraph><paragraph>[]bar</paragraph>
+					model.change( writer => {
+						writer.addMarker( 'restricted-editing-exception:1', {
+							range: writer.createRangeIn( fiirstParagraph ),
+							usingOperation: true,
+							affectsData: true
+						} );
+					} );
+
+					// <paragraph><marker≥foo</marker></paragraph><paragraph><marker≥[]bar</marker></paragraph>
+					model.change( writer => {
+						writer.addMarker( 'restricted-editing-exception:2', {
+							range: writer.createRangeIn( secondParagraph ),
+							usingOperation: true,
+							affectsData: true
+						} );
+					} );
+
+					backwardCommand.execute();
+					expect( getModelData( model ) ).to.equal( '<paragraph>[]foo</paragraph><paragraph>bar</paragraph>' );
+				} );
+
 				it( 'should move to the closest previous marker', () => {
 					setModelData( model, '<paragraph>foo bar baz qux[]</paragraph>' );