Parcourir la source

Adding limits support to data controller's modifySelection method.

Szymon Kupś il y a 8 ans
Parent
commit
ddca3c40ef

+ 7 - 1
packages/ckeditor5-engine/src/controller/modifyselection.js

@@ -76,7 +76,13 @@ export default function modifySelection( dataController, selection, options = {}
 	}
 
 	// 4. If previous scenarios are false, it means that focus is at the beginning/at the end of element and by
-	// extending we are "leaving" the element. Let's see what is further.
+	// extending we are "leaving" the element.
+	// If the element is registered as `limit` - prevent from "leaving" it.
+	if ( schema.limits.has( value.item.name ) ) {
+		return;
+	}
+
+	// Let's see what is further.
 	next = walker.next();
 
 	// 4.1. Nothing left, so let's stay where we were.

+ 21 - 0
packages/ckeditor5-engine/tests/controller/modifyselection.js

@@ -440,6 +440,27 @@ describe( 'DataController', () => {
 				{ direction: 'backward' }
 			);
 		} );
+
+		describe( 'limits handling', () => {
+			beforeEach( () => {
+				document.schema.registerItem( 'limit' );
+				document.schema.allow( { name: 'limit', inside: '$root' } );
+				document.schema.allow( { name: '$text', inside: 'limit' } );
+			} );
+
+			test(
+				'should not extend to outside of limit element',
+				'<limit>foo[]</limit>',
+				'<limit>foo[]</limit>'
+			);
+
+			test(
+				'should not extend to outside of limit element - backward',
+				'<limit>[]foo</limit>',
+				'<limit>[]foo</limit>',
+				{ direction: 'backward' }
+			);
+		} );
 	} );
 
 	function test( title, input, output, options ) {