Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/extensions/yfm/Emoji/EmojiSuggest/EmojiHandler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type {AutocompleteAction} from '../../../behavior/Autocomplete';

import {EmojiHandler} from './EmojiHandler';

describe('EmojiHandler', () => {
describe('onEnter', () => {
it('should return false when no emoji is selected', () => {
const handler = new EmojiHandler({
defs: {smile: '😀'},
});

const action = {
view: {},
} as AutocompleteAction;

// onEnter called without onOpen/onFilter - no emoji carousel initialized
const result = handler.onEnter(action);

expect(result).toBe(false);
});

it('should return true when emoji is selected', () => {
const handler = new EmojiHandler({
defs: {smile: '😀'},
});

// Access private _emojiCarousel to simulate selected emoji
// @ts-expect-error - accessing private property for testing
handler._emojiCarousel = {
currentItem: {symbol: '😀', origName: 'smile', name: 'smile'},
};

const mockDispatch = jest.fn();
const action = {
view: {
state: {
selection: {empty: true},
},
dispatch: mockDispatch,
},
} as unknown as AutocompleteAction;

const result = handler.onEnter(action);

expect(result).toBe(true);
});
});
});
8 changes: 6 additions & 2 deletions src/extensions/yfm/Emoji/EmojiSuggest/EmojiHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ export class EmojiHandler implements AutocompleteHandler {
onEnter(action: AutocompleteAction): boolean {
this.updateState(action);

this.select();
const emojiDef = this._emojiCarousel?.currentItem;
if (!emojiDef) {
return false;
}

this.select();
return true;
}

Expand Down Expand Up @@ -243,7 +247,7 @@ function filterEmojis(defs: readonly EmojiDef[], text: string): readonly EmojiDe
return byShortcuts.concat(byName);
}

const CHARS_TO_HIDE = 4;
const CHARS_TO_HIDE = 1;
function needToHide(defs: readonly EmojiDef[], text: string): boolean {
let iter = 1;
do {
Expand Down
Loading