Skip to content

Commit 7e67b30

Browse files
committed
fix(Emoji): allow Enter to create new line when no emoji is selected
1 parent 69f2239 commit 7e67b30

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import type {AutocompleteAction} from '../../../behavior/Autocomplete';
2+
3+
import {EmojiHandler} from './EmojiHandler';
4+
5+
describe('EmojiHandler', () => {
6+
describe('onEnter', () => {
7+
it('should return false when no emoji is selected', () => {
8+
const handler = new EmojiHandler({
9+
defs: {smile: '😀'},
10+
});
11+
12+
const action = {
13+
view: {},
14+
} as AutocompleteAction;
15+
16+
// onEnter called without onOpen/onFilter - no emoji carousel initialized
17+
const result = handler.onEnter(action);
18+
19+
expect(result).toBe(false);
20+
});
21+
22+
it('should return true when emoji is selected', () => {
23+
const handler = new EmojiHandler({
24+
defs: {smile: '😀'},
25+
});
26+
27+
// Access private _emojiCarousel to simulate selected emoji
28+
// @ts-expect-error - accessing private property for testing
29+
handler._emojiCarousel = {
30+
currentItem: {symbol: '😀', origName: 'smile', name: 'smile'},
31+
};
32+
33+
const mockDispatch = jest.fn();
34+
const action = {
35+
view: {
36+
state: {
37+
selection: {empty: true},
38+
},
39+
dispatch: mockDispatch,
40+
},
41+
} as unknown as AutocompleteAction;
42+
43+
const result = handler.onEnter(action);
44+
45+
expect(result).toBe(true);
46+
});
47+
});
48+
});

src/extensions/yfm/Emoji/EmojiSuggest/EmojiHandler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,12 @@ export class EmojiHandler implements AutocompleteHandler {
108108
onEnter(action: AutocompleteAction): boolean {
109109
this.updateState(action);
110110

111-
this.select();
111+
const emojiDef = this._emojiCarousel?.currentItem;
112+
if (!emojiDef) {
113+
return false;
114+
}
112115

116+
this.select();
113117
return true;
114118
}
115119

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

246-
const CHARS_TO_HIDE = 4;
250+
const CHARS_TO_HIDE = 1;
247251
function needToHide(defs: readonly EmojiDef[], text: string): boolean {
248252
let iter = 1;
249253
do {

0 commit comments

Comments
 (0)