Пример #1
0
    it("Returns null when quill is not focused.", () => {
        // Sanity check that this would otherwise be a valid mention.
        quill.setContents([{ insert: "@Somebody" }]);
        const selection = { index: 3, length: 0 };
        quill.setSelection(selection);
        expect(getMentionRange(quill, selection)).not.to.eq(null);

        // Actual check.
        button.focus();
        expect(getMentionRange(quill, selection)).to.eq(null);
    });
Пример #2
0
export default function instanceReducer(
    state = initialState,
    action: instanceActions.ActionTypes,
): IEditorInstanceState {
    switch (action.type) {
        case instanceActions.CREATE_INSTANCE: {
            validateIDExistance(state, action);
            return {
                ...state,
                [action.payload.editorID]: defaultInstance,
            };
        }
        case instanceActions.DELETE_INSTANCE: {
            validateIDExistance(state, action);
            const newState = { ...state };
            delete newState[action.payload.editorID];
            return newState;
        }
        case instanceActions.SET_SELECTION: {
            validateIDExistance(state, action);
            const { selection, editorID, quill } = action.payload;
            const instanceState = state[editorID];
            const { lastGoodSelection } = instanceState;

            return {
                ...state,
                [editorID]: {
                    ...instanceState,
                    currentSelection: selection,
                    lastGoodSelection: selection !== null ? selection : lastGoodSelection,
                    mentionSelection: getMentionRange(quill, selection),
                },
            };
        }
        default: {
            return state;
        }
    }
}
Пример #3
0
 it("Returns null if we are inside of a codeblock", () => {
     quill.setContents([{ insert: "@Somebody" }, OpUtils.codeBlock()]);
     const selection = { index: 3, length: 0 };
     quill.setSelection(selection);
     expect(getMentionRange(quill, selection)).to.eq(null);
 });
Пример #4
0
 it(prettyNewline(description) + index, () => {
     expect(getMentionRange(quill, { index, length: 0 })).deep.equals({
         index: 6,
         length: index - 6,
     });
 });