Skip to content

Commit 8b37932

Browse files
committed
fix(desktop): completely disable pinch to zoom
1 parent 68d1755 commit 8b37932

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

packages/desktop/src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"url": "/",
2020
"decorations": true,
2121
"dragDropEnabled": false,
22-
"zoomHotkeysEnabled": true,
22+
"zoomHotkeysEnabled": false,
2323
"titleBarStyle": "Overlay",
2424
"hiddenTitle": true,
2525
"trafficLightPosition": { "x": 12.0, "y": 18.0 }

packages/desktop/src/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @refresh reload
2+
import "./webview-zoom"
23
import { render } from "solid-js/web"
34
import { AppBaseProviders, AppInterface, PlatformProvider, Platform } from "@opencode-ai/app"
45
import { open, save } from "@tauri-apps/plugin-dialog"
@@ -303,11 +304,6 @@ const createPlatform = (password: Accessor<string | null>): Platform => ({
303304

304305
createMenu()
305306

306-
// Stops mousewheel events from reaching Tauri's pinch-to-zoom handler
307-
root?.addEventListener("mousewheel", (e) => {
308-
e.stopPropagation()
309-
})
310-
311307
render(() => {
312308
const [serverPassword, setServerPassword] = createSignal<string | null>(null)
313309
const platform = createPlatform(() => serverPassword())
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
import { invoke } from "@tauri-apps/api/core"
6+
import { type as ostype } from "@tauri-apps/plugin-os"
7+
8+
const OS_NAME = ostype()
9+
10+
let zoomLevel = 1
11+
12+
const MAX_ZOOM_LEVEL = 10
13+
const MIN_ZOOM_LEVEL = 0.2
14+
15+
window.addEventListener("keydown", (event) => {
16+
if (OS_NAME === "macos" ? event.metaKey : event.ctrlKey) {
17+
if (event.key === "-") {
18+
zoomLevel -= 0.2
19+
} else if (event.key === "=" || event.key === "+") {
20+
zoomLevel += 0.2
21+
} else if (event.key === "0") {
22+
zoomLevel = 1
23+
} else {
24+
return
25+
}
26+
zoomLevel = Math.min(Math.max(zoomLevel, MIN_ZOOM_LEVEL), MAX_ZOOM_LEVEL)
27+
invoke("plugin:webview|set_webview_zoom", {
28+
value: zoomLevel,
29+
})
30+
}
31+
})

0 commit comments

Comments
 (0)