mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 15:42:01 +03:00
Merge 94ca952abb into bede889ced
This commit is contained in:
commit
4bb2cfbd00
1 changed files with 22 additions and 20 deletions
|
|
@ -224,26 +224,7 @@ export class SumEditor {
|
||||||
borderLeft: "2px solid var(--caret)",
|
borderLeft: "2px solid var(--caret)",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
EditorView.updateListener.of((u: ViewUpdate) => {
|
EditorView.updateListener.of((u: ViewUpdate) => this.handleUpdate(u)),
|
||||||
if (u.docChanged) {
|
|
||||||
const text = u.state.doc.toString();
|
|
||||||
this.evaluate(text);
|
|
||||||
this.cb.onChange(text);
|
|
||||||
}
|
|
||||||
if (u.geometryChanged || u.viewportChanged || u.docChanged) {
|
|
||||||
this.renderResults();
|
|
||||||
}
|
|
||||||
if (u.selectionSet || u.docChanged) {
|
|
||||||
const sel = u.state.selection.main;
|
|
||||||
if (sel.empty) {
|
|
||||||
this.cb.onSelection(null);
|
|
||||||
} else {
|
|
||||||
const from = u.state.doc.lineAt(sel.from).number - 1;
|
|
||||||
const to = u.state.doc.lineAt(sel.to).number - 1;
|
|
||||||
this.cb.onSelection([from, to]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
@ -322,6 +303,27 @@ export class SumEditor {
|
||||||
this.view.focus();
|
this.view.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleUpdate(u: ViewUpdate): void {
|
||||||
|
if (u.docChanged) {
|
||||||
|
const text = u.state.doc.toString();
|
||||||
|
this.evaluate(text);
|
||||||
|
this.cb.onChange(text);
|
||||||
|
}
|
||||||
|
if (u.geometryChanged || u.viewportChanged || u.docChanged) {
|
||||||
|
this.renderResults();
|
||||||
|
}
|
||||||
|
if (u.selectionSet || u.docChanged) {
|
||||||
|
const sel = u.state.selection.main;
|
||||||
|
if (sel.empty) {
|
||||||
|
this.cb.onSelection(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const from = u.state.doc.lineAt(sel.from).number - 1;
|
||||||
|
const to = u.state.doc.lineAt(sel.to).number - 1;
|
||||||
|
this.cb.onSelection([from, to]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private evaluate(text: string): void {
|
private evaluate(text: string): void {
|
||||||
this.results = this.evaluateDoc(text);
|
this.results = this.evaluateDoc(text);
|
||||||
this.view.dispatch({ effects: setResults.of(this.results) });
|
this.view.dispatch({ effects: setResults.of(this.results) });
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue