Skip to content

Commit

Permalink
Fix (engine): bring back CC to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-stv committed Jul 25, 2023
1 parent 2db5895 commit 450d1dc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
12 changes: 9 additions & 3 deletions packages/ckeditor5-engine/src/view/placeholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '../../theme/placeholder.css';

import type Document from './document';
import type DowncastWriter from './downcastwriter';
import type EditableElement from './editableelement';
import type Element from './element';
import type View from './view';

Expand Down Expand Up @@ -39,9 +40,7 @@ const documentPlaceholders = new WeakMap<Document, Map<Element, PlaceholderConfi
*/
export function enablePlaceholder( { view, element, isDirectHost = true, keepOnFocus = false }: {
view: View;
element: Element & {
placeholder?: string;
};
element: PlaceholderableElement | EditableElement;
isDirectHost?: boolean;
keepOnFocus?: boolean;
} ): void {
Expand Down Expand Up @@ -314,3 +313,10 @@ interface PlaceholderConfig {
keepOnFocus: boolean;
hostElement: Element | null;
}

/**
* Element which could have placeholder.
*/
export type PlaceholderableElement = Element & {
placeholder?: string;
};
4 changes: 2 additions & 2 deletions packages/ckeditor5-engine/tests/view/placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,26 +616,26 @@ describe( 'placeholder', () => {
it( 'should update placeholder when property in editing root is changed', () => {
setData( view, '<div></div><div>{another div}</div>' );

viewRoot.placeholder = 'new placeholder';
enablePlaceholder( {
view,
element: viewRoot,
text: 'foo bar baz'
} );
viewRoot.placeholder = 'new placeholder';

expect( viewRoot.getAttribute( 'data-placeholder' ) ).to.equal( 'new placeholder' );
} );

it( 'should update placeholder when property in editing root is changed (isDirectHost=false)', () => {
setData( view, '<div></div><div>{another div}</div>' );

viewRoot.placeholder = 'new placeholder';
enablePlaceholder( {
view,
element: viewRoot,
text: 'foo bar baz',
isDirectHost: false
} );
viewRoot.placeholder = 'new placeholder';

expect( viewRoot.getChild( 0 ).getAttribute( 'data-placeholder' ) ).to.equal( 'new placeholder' );
} );
Expand Down
5 changes: 3 additions & 2 deletions packages/ckeditor5-heading/src/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
type UpcastElementEvent,
type View,
type ViewElement,
type Writer
type Writer,
type PlaceholderableElement
} from 'ckeditor5/src/engine';

// A list of element names that should be treated by the Title plugin as title-like.
Expand Down Expand Up @@ -354,7 +355,7 @@ export default class Title extends Plugin {

// Attach placeholder to the view title element.
editor.editing.downcastDispatcher.on<DowncastInsertEvent<Element>>( 'insert:title-content', ( evt, data, conversionApi ) => {
const element: ViewElement & { placeholder?: string } = conversionApi.mapper.toViewElement( data.item )!;
const element: PlaceholderableElement = conversionApi.mapper.toViewElement( data.item )!;

element.placeholder = titlePlaceholder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { type Editor, Plugin, type CommandExecuteEvent } from 'ckeditor5/src/core';
import { Element, enablePlaceholder, type DocumentChangeEvent, type DiffItemAttribute } from 'ckeditor5/src/engine';
import { Element, enablePlaceholder, type DocumentChangeEvent, type DiffItemAttribute, PlaceholderableElement } from 'ckeditor5/src/engine';
import { toWidgetEditable } from 'ckeditor5/src/widget';
import type { GetCallback } from 'ckeditor5/src/utils';

Expand Down

0 comments on commit 450d1dc

Please sign in to comment.