Files
MyGoNavi/frontend/src/utils/macWindow.ts
Syngnat faef619413 🐛 fix(mac-window): 修复查询替换框在 macOS 无法关闭
- 放行编辑器和输入控件内的 Escape 按键事件

- 保留 macOS 原生全屏下普通区域的 Escape 抑制逻辑

- 补充 Mac 窗口快捷键回归测试

Refs #433
2026-05-08 23:00:23 +08:00

47 lines
1.3 KiB
TypeScript

export const getMacNativeTitlebarPaddingLeft = (uiScale: number, enabled: boolean): number => {
if (!enabled) {
return Math.max(12, Math.round(16 * uiScale));
}
return Math.max(88, Math.round(96 * uiScale));
};
export const getMacNativeTitlebarPaddingRight = (uiScale: number, enabled: boolean): number => {
if (!enabled) {
return 0;
}
return Math.max(12, Math.round(16 * uiScale));
};
export const shouldHandleMacNativeFullscreenShortcut = (
isMacRuntime: boolean,
useNativeMacWindowControls: boolean,
event: Pick<KeyboardEvent, 'ctrlKey' | 'metaKey' | 'altKey' | 'key'>,
): boolean => {
if (!isMacRuntime || !useNativeMacWindowControls) {
return false;
}
if (!event.ctrlKey || !event.metaKey || event.altKey) {
return false;
}
return String(event.key || '').toLowerCase() === 'f';
};
export const shouldSuppressMacNativeEscapeExit = (
isMacRuntime: boolean,
useNativeMacWindowControls: boolean,
isFullscreen: boolean,
event: Pick<KeyboardEvent, 'key' | 'defaultPrevented'>,
options?: { isEditableTarget?: boolean },
): boolean => {
if (!isMacRuntime || !useNativeMacWindowControls || !isFullscreen) {
return false;
}
if (options?.isEditableTarget) {
return false;
}
if (event.defaultPrevented) {
return false;
}
return String(event.key || '') === 'Escape';
};