From 93485fa840e4438e96c95b9f43f6b600d2c0cd6b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2026 23:46:10 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Extract=20UI=20bindings=20from?= =?UTF-8?q?=20initUI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extracted various inline event bindings and setups from the monolithic `initUI` function into separate, well-named helper functions. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- src/main.ts | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/src/main.ts b/src/main.ts index d0bedf1..629b2fc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -800,13 +800,7 @@ async function initDataAndEngine(): Promise { }); } -async function initUI(): Promise { - - applySettings(); // sets the language before bindSettingsUI renders dynamic labels - bindSettingsUI(); - renderDocList(); - syncTitleField(); - +function bindTitleUI(): void { const titleField = $("#doc-title"); titleField.addEventListener("change", () => { const doc = activeDoc(); @@ -830,7 +824,9 @@ async function initUI(): Promise { titleField.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === "Escape") titleField.blur(); }); +} +function bindMiscUI(): void { $("#total-line").addEventListener("click", () => { const v = $("#total-line").dataset.value; if (v) { @@ -841,6 +837,10 @@ async function initUI(): Promise { $("#open-search").addEventListener("click", () => search.open()); + window.addEventListener("focus", () => { lastWindowFocusAt = performance.now(); }); +} + +async function bindWindowControls(): Promise { if (isTauri()) { const { getCurrentWindow } = await import("@tauri-apps/api/window"); const win = getCurrentWindow(); @@ -849,7 +849,9 @@ async function initUI(): Promise { } else { $("#win-controls").style.display = "none"; } +} +function bindSidebarUI(): void { $("#toggle-sidebar").addEventListener("click", () => { settings.sidebarVisible = !settings.sidebarVisible; $("#sidebar").classList.toggle("hidden", !settings.sidebarVisible); @@ -869,7 +871,9 @@ async function initUI(): Promise { $("#sidebar").classList.add("hidden"); void saveSettings(settings); }); +} +function bindDividerUI(): void { const divider = $("#col-divider"); const wrap = $("#editor-wrap"); divider.addEventListener("mousedown", (e) => { @@ -893,9 +897,9 @@ async function initUI(): Promise { window.addEventListener("mousemove", onMove); window.addEventListener("mouseup", onUp); }); +} - window.addEventListener("focus", () => { lastWindowFocusAt = performance.now(); }); - +function bindKeyboardShortcuts(): void { document.addEventListener("keydown", (e) => { if (e.ctrlKey && !e.shiftKey && e.key.toLowerCase() === "n") { e.preventDefault(); @@ -919,8 +923,9 @@ async function initUI(): Promise { toast(t("copied")); } }); +} - // export button + dropdown +function bindExportUI(): void { const exportBtn = $("#export-btn"); const exportMenu = $("#export-menu"); exportBtn.addEventListener("click", (e) => { @@ -960,12 +965,16 @@ async function initUI(): Promise { } } }); +} +function bindRatesAndMarketUI(): void { $("#rates-info").addEventListener("click", () => void refreshRates(true)); $("#market-info").addEventListener("click", () => void refreshMarket(true)); setInterval(renderRatesInfo, 60_000); setInterval(renderMarketInfo, 60_000); +} +async function bindLifecycle(): Promise { void onFileDrop((content) => newDoc(content)); if (!(await registerHotkey(null, settings.hotkey))) toast(t("hotkeyFailed")); @@ -1000,6 +1009,24 @@ async function initUI(): Promise { setInterval(() => { if (settings.autoUpdateEnabled) void checkUpdate(); }, 6 * 60 * 60 * 1000); } +async function initUI(): Promise { + + applySettings(); // sets the language before bindSettingsUI renders dynamic labels + bindSettingsUI(); + renderDocList(); + syncTitleField(); + + bindTitleUI(); + bindMiscUI(); + await bindWindowControls(); + bindSidebarUI(); + bindDividerUI(); + bindKeyboardShortcuts(); + bindExportUI(); + bindRatesAndMarketUI(); + await bindLifecycle(); +} + async function boot(): Promise { await initSettings(); await initDataAndEngine();