Skip to content

Commit

Permalink
Moved skin tone config from EmojiPicker to EmojiDatabase and extr…
Browse files Browse the repository at this point in the history
…acted reading config to variable.
  • Loading branch information
martnpaneq committed Jan 22, 2025
1 parent 4033ee1 commit 9f6423c
Show file tree
Hide file tree
Showing 4 changed files with 12 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
9 changes: 8 additions & 1 deletion 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,7 +229,7 @@ export default class EmojiMention extends Plugin {

const emojis: Array<MentionFeedObjectItem> = this._emojiDatabasePlugin.getEmojiBySearchQuery( searchQuery )
.map( emoji => {
let text = emoji.skins[ this.editor.config.get( 'emoji.skinTone' ) || '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
2 changes: 1 addition & 1 deletion packages/ckeditor5-emoji/tests/emojimention.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ describe( 'EmojiMention', () => {
editorElement.remove();
} );

it( 'should use default skin tone if emoji does not have variants and skin tone is specified in condfig', async () => {
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 );

Expand Down

0 comments on commit 9f6423c

Please sign in to comment.