Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Got rid of *EditableUIView#enableEditingRootListeners(). Moved to ren…
Browse files Browse the repository at this point in the history
…der() because view document root rendering is postponed now.
  • Loading branch information
oleq committed Jan 25, 2019
1 parent 660d48d commit 432b29b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
47 changes: 25 additions & 22 deletions src/decouplededitorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ export default class DecoupledEditorUI 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.
view.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 DecoupledEditor.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.
view.editable.name = editingRoot.rootName;

// Register the editable UI view in the editor. A single editor instance can aggregate multiple
// editable areas (roots) but the decoupled editor has only one.
this._editableElements.set( editable.name, editableElement );
Expand All @@ -96,23 +96,7 @@ export default class DecoupledEditorUI 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', () => {
view.editable.enableEditingRootListeners();

const placeholderText = editor.config.get( 'placeholder' ) ||
editor.sourceElement && editor.sourceElement.getAttribute( 'placeholder' );

if ( placeholderText ) {
const placeholderElement = getRootPlaceholderElement( editingRoot );

addPlaceholder( editingView, placeholderElement, placeholderText );
}
} );

this._initPlaceholder();
this._initToolbar();
this.fire( 'ready' );
}
Expand All @@ -124,7 +108,6 @@ export default class DecoupledEditorUI extends EditorUI {
const view = this._view;
const editingView = this.editor.editing.view;

view.editable.disableEditingRootListeners();
editingView.detachDomRoot( view.editable.name );
view.destroy();

Expand All @@ -150,4 +133,24 @@ export default class DecoupledEditorUI 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 && editor.sourceElement.getAttribute( 'placeholder' );

if ( placeholderText ) {
const placeholderElement = getRootPlaceholderElement( editingRoot );

addPlaceholder( editingView, placeholderElement, placeholderText );
}
}
}
4 changes: 3 additions & 1 deletion tests/manual/placeholder.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<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>

0 comments on commit 432b29b

Please sign in to comment.