mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 15:42:01 +03:00
avoid rebuilding decoration fields on every editor transaction
highlightField and varHighlightField rebuilt from scratch on every CodeMirror transaction, including ones that touch neither the doc nor the selection (e.g. the setResults effect firing after evaluation). varHighlightField now only rebuilds when the doc or selection actually changed; highlightField remaps existing decorations through doc edits and only does a full rebuild when new results arrive.
This commit is contained in:
parent
00bd1248e1
commit
47beea4652
1 changed files with 8 additions and 4 deletions
|
|
@ -65,8 +65,11 @@ function buildDecorations(state: EditorState): DecorationSet {
|
|||
|
||||
const highlightField = StateField.define<DecorationSet>({
|
||||
create: buildDecorations,
|
||||
update(_value, tr) {
|
||||
return buildDecorations(tr.state);
|
||||
update(value, tr) {
|
||||
const hasResults = tr.effects.some((e) => e.is(setResults));
|
||||
if (hasResults) return buildDecorations(tr.state);
|
||||
if (tr.docChanged) return value.map(tr.changes);
|
||||
return value;
|
||||
},
|
||||
provide: (f) => EditorView.decorations.from(f),
|
||||
});
|
||||
|
|
@ -98,8 +101,9 @@ function buildVarHighlight(state: EditorState): DecorationSet {
|
|||
|
||||
const varHighlightField = StateField.define<DecorationSet>({
|
||||
create: buildVarHighlight,
|
||||
update(_value, tr) {
|
||||
return buildVarHighlight(tr.state);
|
||||
update(value, tr) {
|
||||
if (tr.docChanged || tr.selection) return buildVarHighlight(tr.state);
|
||||
return value;
|
||||
},
|
||||
provide: (f) => EditorView.decorations.from(f),
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue