Skip to content

Commit d756fd2

Browse files
author
阿岳
committed
feat: Esc键关闭所有子窗口,关闭搜索窗口后,自动清空所有闪烁的红框
1 parent 845e434 commit d756fd2

File tree

8 files changed

+57
-0
lines changed

8 files changed

+57
-0
lines changed

app/src/core/service/SubWindow.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ export namespace SubWindow {
101101
subWindowsAtom,
102102
store.get(subWindowsAtom).filter((window) => window.id !== id),
103103
);
104+
105+
// 焦点恢复逻辑:关闭窗口后,将焦点移至 z-index 最高的剩余窗口
106+
const remainingWindows = store.get(subWindowsAtom);
107+
if (remainingWindows.length > 0) {
108+
// 找到 z-index 最高的窗口
109+
const highestZIndexWindow = remainingWindows.reduce((highest, current) =>
110+
current.zIndex > highest.zIndex ? current : highest,
111+
);
112+
focus(highestZIndexWindow.id);
113+
}
104114
});
105115
}, 500);
106116
}
@@ -116,4 +126,24 @@ export namespace SubWindow {
116126
export function get(id: string) {
117127
return store.get(subWindowsAtom).find((window) => window.id === id)!;
118128
}
129+
/**
130+
* 关闭所有打开的子窗口
131+
* 会遍历所有窗口并调用 close(id) 方法
132+
* 每个窗口的关闭动画会独立执行
133+
*/
134+
export function closeAll() {
135+
const windows = store.get(subWindowsAtom);
136+
// 遍历所有窗口并调用 close 方法
137+
// close 方法会自动处理事件监听器的清理
138+
windows.forEach((window) => {
139+
close(window.id);
140+
});
141+
}
142+
/**
143+
* 检查是否有打开的子窗口
144+
* @returns 如果有至少一个打开的窗口则返回 true,否则返回 false
145+
*/
146+
export function hasOpenWindows(): boolean {
147+
return store.get(subWindowsAtom).length > 0;
148+
}
119149
}

app/src/core/service/controlService/shortcutKeysEngine/shortcutKeysRegister.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { RectangleSlideEffect } from "@/core/service/feedbackService/effectEngin
55
import { ViewFlashEffect } from "@/core/service/feedbackService/effectEngine/concrete/ViewFlashEffect";
66
import { ViewOutlineFlashEffect } from "@/core/service/feedbackService/effectEngine/concrete/ViewOutlineFlashEffect";
77
import { Settings } from "@/core/service/Settings";
8+
import { SubWindow } from "@/core/service/SubWindow";
89
import { Themes } from "@/core/service/Themes";
910
import { PenStrokeMethods } from "@/core/stage/stageManager/basicMethods/PenStrokeMethods";
1011
import { ConnectableEntity } from "@/core/stage/stageObject/abstract/ConnectableEntity";
@@ -54,6 +55,17 @@ export const allKeyBinds: KeyBindItem[] = [
5455
isUI: true,
5556
},
5657

58+
/*------- 窗口管理 -------*/
59+
{
60+
id: "closeAllSubWindows",
61+
defaultKey: "Escape",
62+
onPress: () => {
63+
if (!SubWindow.hasOpenWindows()) return;
64+
SubWindow.closeAll();
65+
},
66+
isUI: true,
67+
},
68+
5769
/*------- 基础编辑 -------*/
5870
{
5971
id: "undo",

app/src/locales/en.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,10 @@ keyBinds:
13371337
reverseImageColors:
13381338
title: Reverse Image Colors
13391339
description: Reverse the colors of selected images (makes white background black and vice versa)
1340+
closeAllSubWindows:
1341+
title: Close All Sub-Windows
1342+
description: Closes all currently open sub-windows (e.g., Settings, AI, Color panels) and restores focus to the main stage.
1343+
13401344
effects:
13411345
RectangleLittleNoteEffect:
13421346
title: Rectangle Glimmer Hint Effect

app/src/locales/zh_CN.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,9 @@ keyBinds:
16111611
switchActiveProjectReversed:
16121612
title: 切换当前项目(反序)
16131613
description: 按下后,切换到上一个项目
1614+
closeAllSubWindows:
1615+
title: 关闭所有子窗口
1616+
description: 关闭当前所有打开的子窗口(如设置、AI、颜色面板等),并将焦点恢复至主画布。
16141617

16151618
sounds:
16161619
soundEnabled: 音效开关

app/src/locales/zh_TW.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,5 +1552,8 @@ keyBinds:
15521552
switchActiveProjectReversed:
15531553
title: 切換當前項目(反序)
15541554
description: 按下後,切換到上一個項目
1555+
closeAllSubWindows:
1556+
title: 關閉所有子窗口
1557+
description: 關閉當前所有打開的子窗口(如設置、AI、顏色面板等),並將焦點恢復至主畫布。
15551558
sounds:
15561559
soundEnabled: 音效開關

app/src/locales/zh_TWC.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,5 +1582,8 @@ keyBinds:
15821582
switchActiveProjectReversed:
15831583
title: 切換目前專案(反序)
15841584
description: 按下後,切換到上一個專案
1585+
closeAllSubWindows:
1586+
title: 關閉所有子窗口
1587+
description: 關閉當前所有打開的子窗口(如設置、AI、顏色面板等),並將焦點恢復至主畫布。
15851588
sounds:
15861589
soundEnabled: 音效開關

app/src/sub/FindWindow.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default function FindWindow() {
5656
const clearSearch = () => {
5757
setSearchString("");
5858
setSearchResults([]);
59+
project?.contentSearch.startSearch("", false);
5960
};
6061

6162
useEffect(() => {

app/src/sub/SettingsWindow/keybinds.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ export const shortcutKeysGroups: ShortcutKeysGroup[] = [
503503
"switchActiveProject",
504504
"switchActiveProjectReversed",
505505
"switchStealthMode",
506+
"closeAllSubWindows",
506507
],
507508
},
508509
{

0 commit comments

Comments
 (0)