mirror of
https://github.com/kotaindah55/extended-markdown-syntax.git
synced 2026-07-22 05:38:06 +00:00
perf: add identity checking, avoiding decoration facet recomputation
This commit is contained in:
parent
076ed7d952
commit
47bf42e0fe
1 changed files with 16 additions and 7 deletions
|
|
@ -5,23 +5,32 @@ import { EditorView } from "@codemirror/view";
|
|||
/** Stores only height-altering decorations. */
|
||||
export const decoSetField = StateField.define({
|
||||
create(state) {
|
||||
let builder = state.field(builderField);
|
||||
let holder = state.field(builderField).holder;
|
||||
return {
|
||||
lineBreaksSet: builder.holder.lineBreaksSet,
|
||||
blockOmittedSet: builder.holder.blockOmittedSet
|
||||
lineBreaksSet: holder.lineBreaksSet,
|
||||
blockOmittedSet: holder.blockOmittedSet
|
||||
};
|
||||
},
|
||||
update(decoSet, transaction) {
|
||||
let builder = transaction.state.field(builderField);
|
||||
let holder = transaction.state.field(builderField).holder;
|
||||
// Avoid `EditorView.decorations` recomputation while the sets haven't
|
||||
// changed/updated yet. It's done by returning same object rather than
|
||||
// creating the new one, though the same holder.
|
||||
if (
|
||||
holder.lineBreaksSet === decoSet.lineBreaksSet &&
|
||||
holder.blockOmittedSet === decoSet.blockOmittedSet
|
||||
) { return decoSet }
|
||||
return {
|
||||
lineBreaksSet: builder.holder.lineBreaksSet,
|
||||
blockOmittedSet: builder.holder.blockOmittedSet
|
||||
lineBreaksSet: holder.lineBreaksSet,
|
||||
blockOmittedSet: holder.blockOmittedSet
|
||||
};
|
||||
},
|
||||
provide(field) {
|
||||
// The both sets replace line breaks with "<br>" or hide it. Hence, we
|
||||
// need providing it directly, i.e. not in the view update.
|
||||
return [
|
||||
EditorView.decorations.from(field, set => set.blockOmittedSet),
|
||||
EditorView.decorations.from(field, set => set.lineBreaksSet)
|
||||
]
|
||||
},
|
||||
}
|
||||
});
|
||||
Loading…
Reference in a new issue