private _onKeyDownSuggestingDomEvent()

in packages/roosterjs-react-emoji/lib/plugins/EmojiPlugin.tsx [171:216]


    private _onKeyDownSuggestingDomEvent(event: PluginDomEvent): void {
        // If key is enter, try insert emoji at selection
        // If key is space and selection is shortcut, try insert emoji
        const keyboardEvent = event.rawEvent as KeyboardEvent;
        const selectedEmoji = this._pane.getSelectedEmoji();
        const wordBeforeCursor = this._getWordBeforeCursor(event);

        let emoji: Emoji;
        switch (keyboardEvent.which) {
            case KeyCodes.space:
                // We only want to insert on space if the word before the cursor is a shortcut
                emoji = wordBeforeCursor ? matchShortcut(wordBeforeCursor) : null;
                if (!emoji) {
                    this._setIsSuggesting(false, false);
                }

                break;
            case KeyCodes.enter:
                // check if selection is on the "..." and show full picker if so, otherwise try to apply emoji
                if (this._tryShowFullPicker(event, selectedEmoji, wordBeforeCursor)) {
                    break;
                }

                // We only want to insert on space if the word before the cursor is a shortcut
                // If the timer is not null, that means we have a search queued.
                // Check to see is the word before the cursor matches a shortcut first
                // Otherwise if the search completed and it is a shortcut, insert the first item
                emoji = this._timer ? matchShortcut(wordBeforeCursor) : selectedEmoji;
                break;
            case KeyCodes.left:
            case KeyCodes.right:
                const nextIndex = this._pane.navigate(keyboardEvent.which === KeyCodes.left ? -1 : 1);
                if (nextIndex >= 0) {
                    this._contentEditable.setAttribute(AriaAttributes.ActiveDescendant, this._pane.getEmojiElementIdByIndex(nextIndex));
                }
                this._handleEventOnKeyDown(event);
                break;
            case KeyCodes.escape:
                this._setIsSuggesting(false);
                this._handleEventOnKeyDown(event);
        }

        if (emoji && (this._canUndoEmoji = this._insertEmoji(emoji, wordBeforeCursor))) {
            this._handleEventOnKeyDown(event);
        }
    }