Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(desktop): Mac 上图片查看器双指捏合缩放、双指滑动平移
Dashe30a256444aa
diff --git a/apps/desktop/src/renderer/components/chat/ImageLightbox.tsx b/apps/desktop/src/renderer/components/chat/ImageLightbox.tsxindex ffe5a83a9c..a2409de8c3 100644--- a/apps/desktop/src/renderer/components/chat/ImageLightbox.tsx+++ b/apps/desktop/src/renderer/components/chat/ImageLightbox.tsx@@ -6,9 +6,11 @@* - 遮罩:使用 `--overlay-lightbox` 主题 token,保持 lightbox 遮罩语义一致。* - 图片:`object-fit: contain`,四周保留 40px 安全边距。* - 缩放/平移(手势数学共用 `lightboxGestures`,与 MermaidLightbox 同一套):- * - 滚轮 / 触控板双指捏合(macOS、Windows 精密触摸板的 pinch 都由 Chromium- * 合成为带 ctrlKey 的 wheel 事件)/ Ctrl(⌘)+滚轮 → 以光标为焦点缩放。- * 普通滚轮不区分修饰键也直接缩放(Windows 看图器惯例,鼠标用户单手可缩放)。+ * - 触控板双指捏合(macOS、Windows 精密触摸板的 pinch 都由 Chromium 合成为带+ * ctrlKey 的 wheel 事件)/ Ctrl(⌘)+滚轮 → 以光标为焦点缩放。+ * - macOS:双指滑动(不带修饰键的 wheel)在放大后平移,适配态不响应(与+ * MermaidLightbox 同一惯例)。其它平台普通滚轮不区分修饰键也直接缩放+ * (Windows 看图器惯例,鼠标用户单手可缩放)。* - 双击图片:1x ↔ 2x 切换(以双击点为焦点)。* - 放大后左键拖拽平移;松手时若拖动超过阈值,该次 click 不触发关闭。* - 键盘 +/- 步进缩放,0 重置。翻页(←/→ 或箭头按钮)时视口自动重置。@@ -98,7 +100,9 @@ import {LIGHTBOX_WHEEL_IDLE_MS,LIGHTBOX_ZOOM_STEP,clampScale,+ imageLightboxWheelIntent,type LightboxViewport,+ normalizeWheelDelta,wheelZoomFactor,zoomAtPoint,} from './lightboxGestures';@@ -724,17 +728,28 @@ export function ImageLightbox({// biome-ignore lint/correctness/useExhaustiveDependencies: galleryItems 挂载时固定。}, [index, resetViewport]);- // 滚轮缩放。native listener + passive:false 才能 preventDefault,阻止事件穿透- // 到底下的聊天区,也阻止 Chromium 对 ctrl+wheel 的页面级缩放。- // 不区分修饰键:普通滚轮、Ctrl(⌘)+滚轮、触控板 pinch(Chromium 把 macOS /- // Windows 精密触摸板的捏合合成为 ctrlKey=true 的 wheel)统一以光标为焦点缩放。+ // 滚轮 / 触控板。native listener + passive:false 才能 preventDefault,阻止事件穿透+ // 到底下的聊天区,也阻止 Chromium 对 ctrl+wheel 的页面级缩放。路由见+ // imageLightboxWheelIntent:macOS 双指捏合(Chromium 合成为 ctrlKey=true 的 wheel)+ // 与 ⌘/Ctrl+滚轮以光标为焦点缩放,双指滑动在放大后平移;其它平台照旧所有滚轮+ // 都缩放(Windows 看图器惯例)。useEffect(() => {const overlay = overlayRef.current;if (!overlay) return;const onWheel = (e: globalThis.WheelEvent) => {e.preventDefault();- if (e.deltaY === 0) return;const current = viewportRef.current;+ const intent = imageLightboxWheelIntent(e, isMacPlatform(), current.scale);+ if (intent === 'none') return;+ if (intent === 'pan') {+ markWheeling();+ applyViewport({+ ...current,+ tx: current.tx - normalizeWheelDelta(e.deltaX, e.deltaMode),+ ty: current.ty - normalizeWheelDelta(e.deltaY, e.deltaMode),+ });+ return;+ }const rect = overlay.getBoundingClientRect();const point = {// 光标相对 overlay 中心的坐标。图片由 flex 居中,其盒中心与 overlay 中心diff --git a/apps/desktop/src/renderer/components/chat/__tests__/lightboxGestures.test.ts b/apps/desktop/src/renderer/components/chat/__tests__/lightboxGestures.test.tsindex f6e33009ec..ae1d48c9a2 100644--- a/apps/desktop/src/renderer/components/chat/__tests__/lightboxGestures.test.ts+++ b/apps/desktop/src/renderer/components/chat/__tests__/lightboxGestures.test.ts@@ -7,6 +7,7 @@ import {clampScale,wheelZoomFactor,zoomAtPoint,+ imageLightboxWheelIntent,} from '../lightboxGestures';describe('lightboxGestures', () => {@@ -63,3 +64,33 @@ describe('lightboxGestures', () => {expect(wheelZoomFactor(1, 1)).toBeCloseTo(wheelZoomFactor(16), 12);});});++describe('imageLightboxWheelIntent', () => {+ const wheel = (over: Partial<{ ctrlKey: boolean; metaKey: boolean; deltaX: number; deltaY: number }>) => ({+ ctrlKey: false,+ metaKey: false,+ deltaX: 0,+ deltaY: 0,+ ...over,+ });++ it('macOS: pinch (ctrl) and ⌘ + wheel zoom', () => {+ expect(imageLightboxWheelIntent(wheel({ ctrlKey: true, deltaY: -3 }), true, 1)).toBe('zoom');+ expect(imageLightboxWheelIntent(wheel({ metaKey: true, deltaY: 40 }), true, 2)).toBe('zoom');+ expect(imageLightboxWheelIntent(wheel({ ctrlKey: true, deltaX: 5 }), true, 2)).toBe('none');+ });++ it('macOS: two-finger scroll pans only while zoomed in', () => {+ expect(imageLightboxWheelIntent(wheel({ deltaY: 12 }), true, 1)).toBe('none');+ expect(imageLightboxWheelIntent(wheel({ deltaX: -8 }), true, 2)).toBe('pan');+ expect(imageLightboxWheelIntent(wheel({ deltaY: 12 }), true, 2)).toBe('pan');+ expect(imageLightboxWheelIntent(wheel({}), true, 2)).toBe('none');+ });++ it('other platforms: every vertical wheel zooms (unchanged)', () => {+ expect(imageLightboxWheelIntent(wheel({ deltaY: 100 }), false, 1)).toBe('zoom');+ expect(imageLightboxWheelIntent(wheel({ deltaY: -100 }), false, 3)).toBe('zoom');+ expect(imageLightboxWheelIntent(wheel({ ctrlKey: true, deltaY: -2 }), false, 1)).toBe('zoom');+ expect(imageLightboxWheelIntent(wheel({ deltaX: 30 }), false, 2)).toBe('none');+ });+});diff --git a/apps/desktop/src/renderer/components/chat/lightboxGestures.ts b/apps/desktop/src/renderer/components/chat/lightboxGestures.tsindex 8c5c68af02..8f8be558e9 100644--- a/apps/desktop/src/renderer/components/chat/lightboxGestures.ts+++ b/apps/desktop/src/renderer/components/chat/lightboxGestures.ts@@ -103,3 +103,27 @@ export function zoomAtPoint(ty: point.cy - (point.cy - viewport.ty) * ratio,};}++/** What a single wheel event should do in the image lightbox. */+export type ImageLightboxWheelIntent = 'zoom' | 'pan' | 'none';++/**+ * Route one wheel event for ImageLightbox.+ *+ * - macOS follows the trackpad convention (same as MermaidLightbox): a pinch+ * (Chromium delivers it as wheel + ctrlKey) or ⌘/Ctrl + wheel zooms; a plain+ * two-finger scroll pans while zoomed in and does nothing at fit scale.+ * - Other platforms keep the Windows image-viewer convention: every wheel event+ * zooms (one-handed mouse zoom), including precision-touchpad pinch.+ */+export function imageLightboxWheelIntent(+ event: { ctrlKey: boolean; metaKey: boolean; deltaX: number; deltaY: number },+ isMac: boolean,+ scale: number,+): ImageLightboxWheelIntent {+ if (!isMac || event.ctrlKey || event.metaKey) {+ return event.deltaY === 0 ? 'none' : 'zoom';+ }+ if (scale <= 1 || (event.deltaX === 0 && event.deltaY === 0)) return 'none';+ return 'pan';+}