private _onKeyUpDomEvent()

in packages/roosterjs-react-emoji/lib/plugins/EmojiPlugin.tsx [260:287]


    private _onKeyUpDomEvent(event: PluginDomEvent): void {
        if (this._eventHandledOnKeyDown) {
            return;
        }

        const keyboardEvent = event.rawEvent as KeyboardEvent;
        const wordBeforeCursor = this._getWordBeforeCursor(event);
        if ((keyboardEvent.which === KEYCODE_COLON || keyboardEvent.which === KEYCODE_COLON_FIREFOX) && wordBeforeCursor === ":") {
            const { onKeyboardTriggered = NullFunction } = this.options;
            this._setIsSuggesting(true);
            onKeyboardTriggered();
        } else if (wordBeforeCursor) {
            const cursorData = cacheGetContentSearcher(event, this._editor);
            const charBeforeCursor = cursorData ? cursorData.getSubStringBefore(1) : null;

            // It is possible that the word before the cursor is ahead of the pluginEvent we are handling
            // ex. WordBeforeCursor is ":D"" but the event we are currently handling is for the : key
            // Check that the char before the cursor is actually the key event we are currently handling
            // Otherwise we set canUndoEmoji to early and user is unable to backspace undo on the inserted emoji
            if (keyboardEvent.key === charBeforeCursor) {
                const emoji = matchShortcut(wordBeforeCursor);
                if (emoji && this._insertEmoji(emoji, wordBeforeCursor)) {
                    clearContentSearcherCache(event);
                    this._canUndoEmoji = true;
                }
            }
        }
    }