mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-06 10:31:30 +08:00
🐛 fix(mac-window): 修复查询替换框在 macOS 无法关闭
- 放行编辑器和输入控件内的 Escape 按键事件 - 保留 macOS 原生全屏下普通区域的 Escape 抑制逻辑 - 补充 Mac 窗口快捷键回归测试 Refs #433
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,10 +31,14 @@ export const shouldSuppressMacNativeEscapeExit = (
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user