8
0
Просмотр исходного кода

Simplified the implementation.

Kamil Piechaczek 6 лет назад
Родитель
Сommit
988f85da00
1 измененных файлов с 5 добавлено и 11 удалено
  1. 5 11
      packages/ckeditor5-horizontal-line/src/horizontalrulecommand.js

+ 5 - 11
packages/ckeditor5-horizontal-line/src/horizontalrulecommand.js

@@ -44,23 +44,17 @@ export default class HorizontalRuleCommand extends Command {
 
 			let nextElement = horizontalElement.nextSibling;
 
-			// Check whether the element next to inserted horizontal rule can contain a text.
-			// If so, let's put a selection at the beginning of the element.
-			if ( nextElement && model.schema.checkChild( nextElement, '$text' ) ) {
-				writer.setSelection( nextElement, 0 );
-
-				return;
-			}
+			// Check whether an element next to the inserted horizontal rule is defined and can contain a text.
+			const canSetSelection = nextElement && model.schema.checkChild( nextElement, '$text' );
 
-			// If the element is missing or it's not a paragraph, but the paragraph could be inserted
-			// next to the horizontal rule, let's add it.
-			if ( !( nextElement && nextElement.is( 'paragraph' ) ) && model.schema.checkChild( horizontalElement.parent, 'paragraph' ) ) {
+			// If the element is missing, but a paragraph could be inserted next to the horizontal rule, let's add it.
+			if ( !canSetSelection && model.schema.checkChild( horizontalElement.parent, 'paragraph' ) ) {
 				nextElement = writer.createElement( 'paragraph' );
 
 				writer.insert( nextElement, writer.createPositionAfter( horizontalElement ) );
 			}
 
-			// Put the selection at the beginning of the element.
+			// Put the selection inside the element, at the beginning.
 			if ( nextElement ) {
 				writer.setSelection( nextElement, 0 );
 			}