8
0
فهرست منبع

Explained one decision and clarified the code.

Piotrek Koszuliński 7 سال پیش
والد
کامیت
da205cb689
2فایلهای تغییر یافته به همراه17 افزوده شده و 4 حذف شده
  1. 16 4
      packages/ckeditor5-enter/src/shiftentercommand.js
  2. 1 0
      packages/ckeditor5-enter/tests/shiftentercommand.js

+ 16 - 4
packages/ckeditor5-enter/src/shiftentercommand.js

@@ -81,15 +81,27 @@ function softBreakAction( model, writer, selection ) {
 		const leaveUnmerged = !( range.start.isAtStart && range.end.isAtEnd );
 		model.deleteContent( selection, { leaveUnmerged } );
 
-		// Partially selected elements.
+		// Selection within one element:
 		//
 		// <h>x[xx]x</h>		-> <h>x^x</h>			-> <h>x<br>^x</h>
 		if ( isContainedWithinOneElement ) {
 			insertBreak( writer, selection.focus );
 		}
-
-		if ( leaveUnmerged && !isContainedWithinOneElement ) {
-			writer.setSelection( endElement, 0 );
+		// Selection over multiple elements.
+		//
+		// <h>x[x</h><p>y]y<p>	-> <h>x^</h><p>y</p>	-> <h>x</h><p>^y</p>
+		//
+		// We chose not to insert a line break in this case because:
+		//
+		// * it's not a very common scenario,
+		// * it actually surprised me when I saw "expected behaviour" in real life.
+		//
+		// It's ok if the user will need to be more specific where they want the <br> to be inserted.
+		else {
+			// Move the selection to the 2nd element (last step of the example above).
+			if ( leaveUnmerged ) {
+				writer.setSelection( endElement, 0 );
+			}
 		}
 	}
 }

+ 1 - 0
packages/ckeditor5-enter/tests/shiftentercommand.js

@@ -134,6 +134,7 @@ describe( 'ShiftEnterCommand', () => {
 				'<p>x</p><p><softBreak></softBreak>[]</p><p>y</p>'
 			);
 
+			// See: comment in softBreakAction().
 			test(
 				'leaves one empty element after two were fully selected',
 				'<p>[abc</p><p>def]</p>',