From b2a95d79fa6cff8293eaa1aadeeae90992ea7fbe Mon Sep 17 00:00:00 2001 From: mgt Date: Sat, 29 Jul 2023 15:11:50 +0800 Subject: [PATCH] fix for browser and vscode --- addons/frontend/index.html | 2 +- addons/frontend/src/global.d.ts | 1 + addons/frontend/src/svg-doc.ts | 10 ++++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/frontend/index.html b/addons/frontend/index.html index ab727961..0ce369db 100644 --- a/addons/frontend/index.html +++ b/addons/frontend/index.html @@ -8,7 +8,7 @@ - +
diff --git a/addons/frontend/src/global.d.ts b/addons/frontend/src/global.d.ts index 1de3ea82..f023d7b6 100644 --- a/addons/frontend/src/global.d.ts +++ b/addons/frontend/src/global.d.ts @@ -4,3 +4,4 @@ interface Window { handleTypstLocation(elem: Element, page: number, x: number, y: number); typstWebsocket: WebSocket; } +const acquireVsCodeApi: any; diff --git a/addons/frontend/src/svg-doc.ts b/addons/frontend/src/svg-doc.ts index 860b6323..68e50032 100644 --- a/addons/frontend/src/svg-doc.ts +++ b/addons/frontend/src/svg-doc.ts @@ -21,7 +21,7 @@ export class SvgDocument { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.3, 1.5, 1.7, 1.9, 2.1, 2.4, 2.7, 3, 3.3, 3.7, 4.1, 4.6, 5.1, 5.7, 6.3, 7, 7.7, 8.5, 9.4, 10, ]; - this.hookedElem.addEventListener("wheel", (event) => { + const wheelEventHandler = (event: WheelEvent) => { if (event.ctrlKey) { event.preventDefault(); @@ -59,7 +59,13 @@ export class SvgDocument { this.hookedElem.style.transformOrigin = "0 0"; this.hookedElem.style.transform = `scale(${this.currentScale})`; } - }); + }; + const vscodeAPI = typeof (acquireVsCodeApi) !== "undefined"; + if (vscodeAPI) { + window.addEventListener("wheel", wheelEventHandler); + } else { + document.body.addEventListener("wheel", wheelEventHandler, { passive: false }); + } } rescale() {