@codemirror/state#StateEffect TypeScript Examples

The following examples show how to use @codemirror/state#StateEffect. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmbedDecoration.ts    From obsidian-plantuml with MIT License 6 votes vote down vote up
////////////////
// Utility Code
////////////////

// Generic helper for creating pairs of editor state fields and
// effects to model imperatively updated decorations.
// source: https://github.com/ChromeDevTools/devtools-frontend/blob/8f098d33cda3dd94b53e9506cd3883d0dccc339e/front_end/panels/sources/DebuggerPlugin.ts#L1722
function defineStatefulDecoration(): {
    update: StateEffectType<DecorationSet>;
    field: StateField<DecorationSet>;
} {
    const update = StateEffect.define<DecorationSet>();
    const field = StateField.define<DecorationSet>({
        create(): DecorationSet {
            return Decoration.none;
        },
        update(deco, tr): DecorationSet {
            return tr.effects.reduce((deco, effect) => (effect.is(update) ? effect.value : deco), deco.map(tr.changes));
        },
        provide: field => EditorView.decorations.from(field),
    });
    return {update, field};
}
Example #2
Source File: code.tsx    From nota with MIT License 5 votes vote down vote up
addHighlight = StateEffect.define<{ from: number; to: number; color: string }>()
Example #3
Source File: code.tsx    From nota with MIT License 5 votes vote down vote up
clearHighlights = StateEffect.define()