From 92a61fce946593d17be549713d8f70ffdf852a4d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 7 Oct 2026 03:57:12 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20[code=20health=20improvement]=20?= =?UTF-8?q?Extract=20EditorView=20update=20listener=20to=20reduce=20nestin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- src/ui/editor.ts | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/ui/editor.ts b/src/ui/editor.ts index dea37c8..522ca67 100644 --- a/src/ui/editor.ts +++ b/src/ui/editor.ts @@ -224,26 +224,7 @@ export class SumEditor { borderLeft: "2px solid var(--caret)", }, }), - EditorView.updateListener.of((u: ViewUpdate) => { - 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]); - } - } - }), + EditorView.updateListener.of((u: ViewUpdate) => this.handleUpdate(u)), ], }), }); @@ -322,6 +303,27 @@ export class SumEditor { 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); + } 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]); + } + } + } + private evaluate(text: string): void { this.results = this.evaluateDoc(text); this.view.dispatch({ effects: setResults.of(this.results) });