Преглед на файлове

Got rid of editable.enableEditingRootListeners() in the InlineEditorUI. The placeholder initation does not need to wait for editor#dataReady any longer.

Aleksander Nowodzinski преди 6 години
родител
ревизия
420e6141bc

+ 24 - 20
packages/ckeditor5-editor-inline/src/inlineeditorui.js

@@ -71,16 +71,16 @@ export default class InlineEditorUI extends EditorUI {
 		const editable = view.editable;
 		const editingRoot = editingView.document.getRoot();
 
+		// The editable UI and editing root should share the same name. Then name is used
+		// to recognize the particular editable, for instance in ARIA attributes.
+		editable.name = editingRoot.rootName;
+
 		view.render();
 
 		// The editable UI element in DOM is available for sure only after the editor UI view has been rendered.
 		// But it can be available earlier if a DOM element has been passed to InlineEditor.create().
 		const editableElement = editable.element;
 
-		// The editable UI and editing root should share the same name. Then name is used
-		// to recognize the particular editable, for instance in ARIA attributes.
-		editable.name = editingRoot.rootName;
-
 		// Register the editable UI view in the editor. A single editor instance can aggregate multiple
 		// editable areas (roots) but the inline editor has only one.
 		this._editableElements.set( editable.name, editableElement );
@@ -103,22 +103,7 @@ export default class InlineEditorUI extends EditorUI {
 		// of the editor's engine. This is where the engine meets the UI.
 		editingView.attachDomRoot( editableElement );
 
-		// The UI must wait until the data is ready to attach certain actions that operate
-		// on the editing view–level. They use the view writer to set attributes on the editable
-		// element and doing so before data is loaded into the model (ready) would destroy the
-		// original content.
-		editor.on( 'dataReady', () => {
-			editable.enableEditingRootListeners();
-
-			const placeholderText = editor.config.get( 'placeholder' ) || editor.sourceElement.getAttribute( 'placeholder' );
-
-			if ( placeholderText ) {
-				const placeholderElement = getRootPlaceholderElement( editingRoot );
-
-				addPlaceholder( editingView, placeholderElement, placeholderText );
-			}
-		} );
-
+		this._initPlaceholder();
 		this._initToolbar();
 		this.fire( 'ready' );
 	}
@@ -176,4 +161,23 @@ export default class InlineEditorUI extends EditorUI {
 			toolbar
 		} );
 	}
+
+	/**
+	 * Enable the placeholder text on the editing root, if any was configured.
+	 *
+	 * @private
+	 */
+	_initPlaceholder() {
+		const editor = this.editor;
+		const editingView = editor.editing.view;
+		const editingRoot = editingView.document.getRoot();
+
+		const placeholderText = editor.config.get( 'placeholder' ) || editor.sourceElement.getAttribute( 'placeholder' );
+
+		if ( placeholderText ) {
+			const placeholderElement = getRootPlaceholderElement( editingRoot );
+
+			addPlaceholder( editingView, placeholderElement, placeholderText );
+		}
+	}
 }

+ 2 - 0
packages/ckeditor5-editor-inline/tests/manual/inlineeditor.html

@@ -4,6 +4,8 @@
 </p>
 
 <div id="editor-1" contenteditable="true" class="custom-class" custom-attr="foo">
+	<h2>Editor 1</h2>
+	<p>This is an editor instance.</p>
 </div>
 
 <div id="editor-2" class="custom-class" custom-attr="foo">

+ 1 - 1
packages/ckeditor5-editor-inline/tests/manual/placeholder.html

@@ -1,3 +1,3 @@
-<div id="editor-1" placeholder="Placeholder from the attribute"></div>
+<div id="editor-1" placeholder="Placeholder from the attribute"><p>Remove this text to see the placeholder.</p></div>
 <br />
 <div id="editor-2" placeholder="Placeholder from the attribute"></div>