8
0
Quellcode durchsuchen

Added the insert paragraph on (Shift+)Enter feature that used to be a part of the Widget plugin to the WidgetTypeAround plugin.

Aleksander Nowodzinski vor 5 Jahren
Ursprung
Commit
8a3d137a31
1 geänderte Dateien mit 18 neuen und 0 gelöschten Zeilen
  1. 18 0
      packages/ckeditor5-widget/src/widgettypearound/widgettypearound.js

+ 18 - 0
packages/ckeditor5-widget/src/widgettypearound/widgettypearound.js

@@ -374,7 +374,25 @@ export default class WidgetTypeAround extends Plugin {
 		const editingView = editor.editing.view;
 
 		this.listenTo( editingView.document, 'enter', ( evt, domEventData ) => {
+			const selectedViewElement = editingView.document.selection.getSelectedElement();
+			const selectedModelElement = editor.editing.mapper.toModelElement( selectedViewElement );
+			const schema = editor.model.schema;
+			let wasHandled;
+
+			// First check if the widget is selected and there's a type around selection attribute associated
+			// with the "fake caret" that would tell where to insert a new paragraph.
 			if ( this._insertParagraphAccordingToSelectionAttribute() ) {
+				wasHandled = true;
+			}
+			// Then, if there is no selection attribute associated with the "fake caret", check if the widget
+			// simply is selected and create a new paragraph according to the keystroke (Shift+)Enter.
+			else if ( isTypeAroundWidget( selectedViewElement, selectedModelElement, schema ) ) {
+				this._insertParagraph( selectedViewElement, domEventData.isSoft ? 'before' : 'after' );
+
+				wasHandled = true;
+			}
+
+			if ( wasHandled ) {
 				domEventData.preventDefault();
 				evt.stop();
 			}