From faef6194132168ee3e910f0e343226312f564c80 Mon Sep 17 00:00:00 2001 From: Syngnat Date: Fri, 8 May 2026 23:00:23 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(mac-window):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=9F=A5=E8=AF=A2=E6=9B=BF=E6=8D=A2=E6=A1=86=E5=9C=A8?= =?UTF-8?q?=20macOS=20=E6=97=A0=E6=B3=95=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 放行编辑器和输入控件内的 Escape 按键事件 - 保留 macOS 原生全屏下普通区域的 Escape 抑制逻辑 - 补充 Mac 窗口快捷键回归测试 Refs #433 --- frontend/src/App.tsx | 8 +++++++- frontend/src/utils/macWindow.test.ts | 10 ++++++++++ frontend/src/utils/macWindow.ts | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 72a9481..4fe8a1a 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -2371,7 +2371,13 @@ function App() { } const handleMacNativeEscapeCapture = (event: KeyboardEvent) => { - if (!shouldSuppressMacNativeEscapeExit(isMacRuntime, useNativeMacWindowControls, useStore.getState().windowState === 'fullscreen', event)) { + if (!shouldSuppressMacNativeEscapeExit( + isMacRuntime, + useNativeMacWindowControls, + useStore.getState().windowState === 'fullscreen', + event, + { isEditableTarget: isEditableElement(event.target) }, + )) { return; } event.preventDefault(); diff --git a/frontend/src/utils/macWindow.test.ts b/frontend/src/utils/macWindow.test.ts index 5e1d0d0..6620ac4 100644 --- a/frontend/src/utils/macWindow.test.ts +++ b/frontend/src/utils/macWindow.test.ts @@ -44,4 +44,14 @@ describe('macWindow helpers', () => { expect(shouldSuppressMacNativeEscapeExit(true, true, true, { key: 'Enter', defaultPrevented: false })).toBe(false); expect(shouldSuppressMacNativeEscapeExit(true, true, true, { key: 'Escape', defaultPrevented: true })).toBe(false); }); + + it('does not suppress Escape for editable targets so editor widgets can close', () => { + expect(shouldSuppressMacNativeEscapeExit( + true, + true, + true, + { key: 'Escape', defaultPrevented: false }, + { isEditableTarget: true }, + )).toBe(false); + }); }); diff --git a/frontend/src/utils/macWindow.ts b/frontend/src/utils/macWindow.ts index bb156f8..d5f3dde 100644 --- a/frontend/src/utils/macWindow.ts +++ b/frontend/src/utils/macWindow.ts @@ -31,10 +31,14 @@ export const shouldSuppressMacNativeEscapeExit = ( useNativeMacWindowControls: boolean, isFullscreen: boolean, event: Pick, + options?: { isEditableTarget?: boolean }, ): boolean => { if (!isMacRuntime || !useNativeMacWindowControls || !isFullscreen) { return false; } + if (options?.isEditableTarget) { + return false; + } if (event.defaultPrevented) { return false; }