@codemirror/state#StateEffectType TypeScript Examples
The following examples show how to use
@codemirror/state#StateEffectType.
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 |
////////////////
// 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};
}