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

Merge pull request #35 from ckeditor/t/34

Changed: Enter at the end of element should create new element.
Piotrek Koszuliński пре 9 година
родитељ
комит
af8f83679a
1 измењених фајлова са 13 додато и 1 уклоњено
  1. 13 1
      packages/ckeditor5-enter/src/entercommand.js

+ 13 - 1
packages/ckeditor5-enter/src/entercommand.js

@@ -4,6 +4,7 @@
  */
 
 import Command from '../core/command/command.js';
+import Position from '../engine/model/position.js';
 
 /**
  * Enter command. It is used by the {@link enter.Enter Enter feature} to handle the <kbd>Enter</kbd> key.
@@ -75,6 +76,17 @@ function enterBlock( batch, selection ) {
 }
 
 function splitBlock( batch, selection, splitPos ) {
-	batch.split( splitPos );
+	if ( splitPos.isAtEnd ) {
+		// If the split is at the end of element, instead of splitting, just create a clone of position's parent
+		// element and insert it after cloned element. The result is the same but less operations are taken
+		// and it's more semantically correct (when it comes to operational transformation).
+		const oldElement = splitPos.parent;
+		const newElement = new oldElement.constructor( oldElement.name, oldElement.getAttributes() );
+
+		batch.insert( Position.createAfter( splitPos.parent ), newElement );
+	} else {
+		batch.split( splitPos );
+	}
+
 	selection.collapse( splitPos.parent.nextSibling );
 }