|
|
@@ -268,16 +268,16 @@ export default class Widget extends Plugin {
|
|
|
_handleEnterKey( isBackwards ) {
|
|
|
const model = this.editor.model;
|
|
|
const modelSelection = model.document.selection;
|
|
|
- const objectElement = modelSelection.getSelectedElement();
|
|
|
+ const selectedElement = modelSelection.getSelectedElement();
|
|
|
|
|
|
- if ( objectElement && model.schema.isObject( objectElement ) && !model.schema.isInline( objectElement ) ) {
|
|
|
+ if ( shouldInsertParagraph( selectedElement, model.schema ) ) {
|
|
|
model.change( writer => {
|
|
|
- let position = writer.createPositionAt( objectElement, isBackwards ? 'before' : 'after' );
|
|
|
+ let position = writer.createPositionAt( selectedElement, isBackwards ? 'before' : 'after' );
|
|
|
const paragraph = writer.createElement( 'paragraph' );
|
|
|
|
|
|
// Split the parent when inside a block element.
|
|
|
// https://github.com/ckeditor/ckeditor5/issues/1529
|
|
|
- if ( model.schema.isBlock( objectElement.parent ) ) {
|
|
|
+ if ( model.schema.isBlock( selectedElement.parent ) ) {
|
|
|
const paragraphLimit = model.schema.findAllowedParent( position, paragraph );
|
|
|
|
|
|
position = writer.split( position, paragraphLimit ).position;
|
|
|
@@ -451,3 +451,11 @@ function isChild( element, parent ) {
|
|
|
|
|
|
return Array.from( element.getAncestors() ).includes( parent );
|
|
|
}
|
|
|
+
|
|
|
+// Checks if enter key should insert paragraph. This should be done only on elements of type object (excluding inline objects).
|
|
|
+//
|
|
|
+// @param {module:engine/model/element~Element} element And element to check.
|
|
|
+// @param {module:engine/model/schema~Schema} schema
|
|
|
+function shouldInsertParagraph( element, schema ) {
|
|
|
+ return element && schema.isObject( element ) && !schema.isInline( element );
|
|
|
+}
|