import { sendTriggerEvent } from "./send-trigger-event";
export const getTextInputHandler = (contentConverter, triggerCharacters, updateActiveTrigger) => {
    return (view, _from, _to, text) => {
        if (!triggerCharacters.includes(text)) {
            return false;
        }
        const doc = view.state.doc;
        const precedingText = doc.textBetween(_from - 1, _from, '');
        if (/\s/.test(precedingText) || precedingText === '') {
            const trigger = {
                character: text,
                position: _from,
            };
            updateActiveTrigger(trigger);
            sendTriggerEvent('triggerStart', view, contentConverter, trigger, text);
        }
        return false;
    };
};
