Skip to content

Commit

Permalink
fix (engine): code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-stv committed Jul 25, 2023
1 parent a753adc commit 32d4d8f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
4 changes: 3 additions & 1 deletion packages/ckeditor5-editor-balloon/src/ballooneditorui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ export default class BalloonEditorUI extends EditorUI {
placeholderText = typeof placeholder === 'string' ? placeholder : placeholder[ editingRoot.rootName ];
}

editingRoot.placeholder = placeholderText;
if ( placeholderText ) {
editingRoot.placeholder = placeholderText;
}

enablePlaceholder( {
view: editingView,
Expand Down
4 changes: 3 additions & 1 deletion packages/ckeditor5-editor-decoupled/src/decouplededitorui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ export default class DecoupledEditorUI extends EditorUI {
placeholderText = typeof placeholder === 'string' ? placeholder : placeholder[ editingRoot.rootName ];
}

editingRoot.placeholder = placeholderText;
if ( placeholderText ) {
editingRoot.placeholder = placeholderText;
}

enablePlaceholder( {
view: editingView,
Expand Down
4 changes: 3 additions & 1 deletion packages/ckeditor5-editor-inline/src/inlineeditorui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ export default class InlineEditorUI extends EditorUI {
placeholderText = typeof placeholder === 'string' ? placeholder : placeholder[ editingRoot.rootName ];
}

editingRoot.placeholder = placeholderText;
if ( placeholderText ) {
editingRoot.placeholder = placeholderText;
}

if ( placeholderText ) {
enablePlaceholder( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ export default class MultiRootEditorUI extends EditorUI {
const editingView = this.editor.editing.view;
const editingRoot = editingView.document.getRoot( editable.name! )!;

editingRoot.placeholder = placeholder;
if ( placeholder ) {
editingRoot.placeholder = placeholder;
}

enablePlaceholder( {
view: editingView,
Expand Down
4 changes: 3 additions & 1 deletion packages/ckeditor5-engine/src/view/editableelement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export default class EditableElement extends ObservableMixin( ContainerElement )
declare public isFocused: boolean;

/**
* Placeholder of current editable element.
* Placeholder of editable element. Could be updated.
*
* editor.editing.view.document.getRoot( 'main' ).placeholder = 'New placeholder';
*
* @observable
*/
Expand Down
19 changes: 7 additions & 12 deletions packages/ckeditor5-engine/src/view/placeholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const documentPlaceholders = new WeakMap<Document, Map<Element, PlaceholderConfi
* @param options Configuration options of the placeholder.
* @param options.view Editing view instance.
* @param options.element Element that will gain a placeholder. See `options.isDirectHost` to learn more.
* @param options.text Placeholder text.
* @param options.isDirectHost If set `false`, the placeholder will not be enabled directly
* in the passed `element` but in one of its children (selected automatically, i.e. a first empty child element).
* Useful when attaching placeholders to elements that can host other elements (not just text), for instance,
Expand Down Expand Up @@ -62,22 +61,18 @@ export function enablePlaceholder( { view, element, isDirectHost = true, keepOnF

if ( element.is( 'editableElement' ) ) {
element.on( 'change:placeholder', ( evtInfo, evt, text ) => {
// Store information about the element placeholder under its document.
documentPlaceholders.get( doc )!.set( element, {
text,
isDirectHost,
keepOnFocus,
hostElement: isDirectHost ? element : null
} );

// Update the placeholders right away.
view.change( writer => updateDocumentPlaceholders( doc, writer ) );
setPlaceholder( text );
} );
}

if ( element.placeholder ) {
setPlaceholder( element.placeholder );
}

function setPlaceholder( text: string ) {
// Store information about the element placeholder under its document.
documentPlaceholders.get( doc )!.set( element, {
text: element.placeholder,
text,
isDirectHost,
keepOnFocus,
hostElement: isDirectHost ? element : null
Expand Down

0 comments on commit 32d4d8f

Please sign in to comment.