8
0
Pārlūkot izejas kodu

Feature: preventing enter command from breaking limit elements.

Szymon Kupś 8 gadi atpakaļ
vecāks
revīzija
658fbc8a1f
1 mainītis faili ar 8 papildinājumiem un 2 dzēšanām
  1. 8 2
      packages/ckeditor5-enter/src/entercommand.js

+ 8 - 2
packages/ckeditor5-enter/src/entercommand.js

@@ -24,7 +24,7 @@ export default class EnterCommand extends Command {
 		const batch = doc.batch();
 
 		doc.enqueueChanges( () => {
-			enterBlock( this.editor.data, batch, doc.selection );
+			enterBlock( this.editor.data, batch, doc.selection, doc.schema );
 
 			this.fire( 'afterExecute', { batch } );
 		} );
@@ -36,12 +36,18 @@ export default class EnterCommand extends Command {
 // @param {engine.controller.DataController} dataController
 // @param {module:engine/model/batch~Batch} batch A batch to which the deltas will be added.
 // @param {module:engine/model/selection~Selection} selection Selection on which the action should be performed.
-function enterBlock( dataController, batch, selection ) {
+// @param {module:engine/model/schema~Schema} schema
+function enterBlock( dataController, batch, selection, schema ) {
 	const isSelectionEmpty = selection.isCollapsed;
 	const range = selection.getFirstRange();
 	const startElement = range.start.parent;
 	const endElement = range.end.parent;
 
+	// Do nothing if selection starts or ends inside `limit` elements.
+	if ( schema.limits.has( startElement.name ) || schema.limits.has( endElement.name ) ) {
+		return;
+	}
+
 	// Don't touch the root.
 	if ( startElement.root == startElement ) {
 		if ( !isSelectionEmpty ) {