mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-18 03:12:16 +08:00
- 放行编辑器和输入控件内的 Escape 按键事件 - 保留 macOS 原生全屏下普通区域的 Escape 抑制逻辑 - 补充 Mac 窗口快捷键回归测试 Refs #433
58 lines
3.0 KiB
TypeScript
58 lines
3.0 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import {
|
|
getMacNativeTitlebarPaddingLeft,
|
|
getMacNativeTitlebarPaddingRight,
|
|
shouldHandleMacNativeFullscreenShortcut,
|
|
shouldSuppressMacNativeEscapeExit,
|
|
} from './macWindow';
|
|
|
|
describe('macWindow helpers', () => {
|
|
it('uses compact padding when native controls are disabled', () => {
|
|
expect(getMacNativeTitlebarPaddingLeft(1, false)).toBe(16);
|
|
expect(getMacNativeTitlebarPaddingRight(1, false)).toBe(0);
|
|
});
|
|
|
|
it('reserves traffic-light safe area when native controls are enabled', () => {
|
|
expect(getMacNativeTitlebarPaddingLeft(1, true)).toBe(96);
|
|
expect(getMacNativeTitlebarPaddingRight(1, true)).toBe(16);
|
|
});
|
|
|
|
it('keeps minimum safe area under small ui scales', () => {
|
|
expect(getMacNativeTitlebarPaddingLeft(0.5, true)).toBe(88);
|
|
expect(getMacNativeTitlebarPaddingRight(0.5, true)).toBe(12);
|
|
});
|
|
|
|
it('matches Control+Command+F only for mac native mode', () => {
|
|
expect(shouldHandleMacNativeFullscreenShortcut(true, true, { ctrlKey: true, metaKey: true, altKey: false, key: 'f' })).toBe(true);
|
|
expect(shouldHandleMacNativeFullscreenShortcut(true, true, { ctrlKey: true, metaKey: true, altKey: false, key: 'F' })).toBe(true);
|
|
});
|
|
|
|
it('rejects conflicting modifiers and non-target keys', () => {
|
|
expect(shouldHandleMacNativeFullscreenShortcut(true, true, { ctrlKey: true, metaKey: true, altKey: true, key: 'f' })).toBe(false);
|
|
expect(shouldHandleMacNativeFullscreenShortcut(true, true, { ctrlKey: true, metaKey: false, altKey: false, key: 'f' })).toBe(false);
|
|
expect(shouldHandleMacNativeFullscreenShortcut(false, true, { ctrlKey: true, metaKey: true, altKey: false, key: 'f' })).toBe(false);
|
|
expect(shouldHandleMacNativeFullscreenShortcut(true, false, { ctrlKey: true, metaKey: true, altKey: false, key: 'f' })).toBe(false);
|
|
expect(shouldHandleMacNativeFullscreenShortcut(true, true, { ctrlKey: true, metaKey: true, altKey: false, key: 'g' })).toBe(false);
|
|
});
|
|
|
|
it('suppresses Escape only in mac native fullscreen mode', () => {
|
|
expect(shouldSuppressMacNativeEscapeExit(true, true, true, { key: 'Escape', defaultPrevented: false })).toBe(true);
|
|
expect(shouldSuppressMacNativeEscapeExit(true, true, false, { key: 'Escape', defaultPrevented: false })).toBe(false);
|
|
expect(shouldSuppressMacNativeEscapeExit(true, false, true, { key: 'Escape', defaultPrevented: false })).toBe(false);
|
|
expect(shouldSuppressMacNativeEscapeExit(false, true, true, { key: 'Escape', defaultPrevented: false })).toBe(false);
|
|
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);
|
|
});
|
|
});
|