Skip to content

Commit

Permalink
Merge pull request #17800 from ckeditor/ck/17778-fix-skin-tone-config
Browse files Browse the repository at this point in the history
Internal: Fixed skin tone in emoji mention to take the default value from emoji config.
  • Loading branch information
martnpaneq authored Jan 23, 2025
2 parents 31969f6 + 9f6423c commit 7919ea0
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/ckeditor5-emoji/src/emojidatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export default class EmojiDatabase extends Plugin {
super( editor );

this.editor.config.define( 'emoji', {
version: 16
version: 16,
skinTone: 'default'
} );

this._emojiDatabase = [];
Expand Down
10 changes: 8 additions & 2 deletions packages/ckeditor5-emoji/src/emojimention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { MentionFeed, MentionFeedObjectItem } from '@ckeditor/ckeditor5-men

import EmojiDatabase from './emojidatabase.js';
import type EmojiPicker from './emojipicker.js';
import type { SkinToneId } from './emojiconfig.js';

const EMOJI_MENTION_MARKER = ':';
const EMOJI_SHOW_ALL_OPTION_ID = ':__EMOJI_SHOW_ALL:';
Expand Down Expand Up @@ -41,6 +42,11 @@ export default class EmojiMention extends Plugin {
*/
private readonly _emojiDropdownLimit: number;

/**
* Defines a skin tone that is set in the emoji config.
*/
private readonly _skinTone: SkinToneId;

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -73,6 +79,7 @@ export default class EmojiMention extends Plugin {
} );

this._emojiDropdownLimit = editor.config.get( 'emoji.dropdownLimit' )!;
this._skinTone = editor.config.get( 'emoji.skinTone' )!;

const mentionFeedsConfigs = editor.config.get( 'mention.feeds' )! as Array<MentionFeed>;
const mergeFieldsPrefix = editor.config.get( 'mergeFields.prefix' )! as string;
Expand Down Expand Up @@ -222,8 +229,7 @@ export default class EmojiMention extends Plugin {

const emojis: Array<MentionFeedObjectItem> = this._emojiDatabasePlugin.getEmojiBySearchQuery( searchQuery )
.map( emoji => {
// TODO: The configuration `emoji.skinTone` option is ignored here.
let text = emoji.skins.default;
let text = emoji.skins[ this._skinTone ] || emoji.skins.default;

if ( this._emojiPickerPlugin ) {
text = emoji.skins[ this._emojiPickerPlugin.skinTone ] || emoji.skins.default;
Expand Down
13 changes: 1 addition & 12 deletions packages/ckeditor5-emoji/src/emojipicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { ButtonView, clickOutsideHandler, ContextualBalloon, Dialog, MenuBarMenuListItemButtonView } from 'ckeditor5/src/ui.js';
import type { PositionOptions } from 'ckeditor5/src/utils.js';
import { type Editor, icons, Plugin } from 'ckeditor5/src/core.js';
import { icons, Plugin } from 'ckeditor5/src/core.js';

import EmojiDatabase from './emojidatabase.js';
import EmojiPickerView from './ui/emojipickerview.js';
Expand Down Expand Up @@ -62,17 +62,6 @@ export default class EmojiPicker extends Plugin {
return true;
}

/**
* @inheritDoc
*/
constructor( editor: Editor ) {
super( editor );

this.editor.config.define( 'emoji', {
skinTone: 'default'
} );
}

/**
* @inheritDoc
*/
Expand Down
79 changes: 79 additions & 0 deletions packages/ckeditor5-emoji/tests/emojimention.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,85 @@ describe( 'EmojiMention', () => {
text: thumbUpItem.skins.default
} );
} );

it( 'should read default skin tone from config', async () => {
const editorElement = document.createElement( 'div' );
document.body.appendChild( editorElement );

const editor = await ClassicTestEditor.create( editorElement, {
plugins: [ EmojiMention, EmojiPicker, Paragraph, Essentials, Mention ],
substitutePlugins: [ EmojiDatabaseMock ],
emoji: {
skinTone: 'medium'
}
} );

const { getEmojiBySearchQuery } = editor.plugins.get( 'EmojiDatabase' );
const thumbUpItem = {
annotation: 'thumbs up',
emoji: '👍️',
skins: {
'default': '👍️',
'light': '👍🏻',
'medium-light': '👍🏼',
'medium': '👍🏽',
'medium-dark': '👍🏾',
'dark': '👍🏿'
}
};

getEmojiBySearchQuery.returns( [ thumbUpItem ] );

const queryEmoji = editor.plugins.get( 'EmojiMention' )._queryEmojiCallbackFactory();
const queryResult = queryEmoji( 'thumbs' );

expect( queryResult.length ).to.equal( 2 );

expect( queryResult[ 0 ] ).to.deep.equal( {
id: ':thumbs up:',
text: thumbUpItem.skins.medium
} );

await editor.destroy();
editorElement.remove();
} );

it( 'should use default skin tone if emoji does not have variants and skin tone is specified in config', async () => {
const editorElement = document.createElement( 'div' );
document.body.appendChild( editorElement );

const editor = await ClassicTestEditor.create( editorElement, {
plugins: [ EmojiMention, EmojiPicker, Paragraph, Essentials, Mention ],
substitutePlugins: [ EmojiDatabaseMock ],
emoji: {
skinTone: 'medium'
}
} );

const { getEmojiBySearchQuery } = editor.plugins.get( 'EmojiDatabase' );
const thumbUpItem = {
annotation: 'thumbs up',
emoji: '👍️',
skins: {
'default': '👍️'
}
};

getEmojiBySearchQuery.returns( [ thumbUpItem ] );

const queryEmoji = editor.plugins.get( 'EmojiMention' )._queryEmojiCallbackFactory();
const queryResult = queryEmoji( 'thumbs' );

expect( queryResult.length ).to.equal( 2 );

expect( queryResult[ 0 ] ).to.deep.equal( {
id: ':thumbs up:',
text: thumbUpItem.skins.default
} );

await editor.destroy();
editorElement.remove();
} );
} );

function simulateTyping( text ) {
Expand Down

0 comments on commit 7919ea0

Please sign in to comment.