Skip to content

Commit ecbb52d

Browse files
committed
fix: windows 上快捷键全改成用 Ctrl,避免按 Alt 导致页面失焦问题
1 parent 7429743 commit ecbb52d

5 files changed

Lines changed: 38 additions & 14 deletions

File tree

src/renderer/src/coder/AppStatusBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ export function AppStatusBar() {
7979
<div className="flex items-center space-x-2 pointer-events-none opacity-50 text-sm gap-1">
8080
<span>
8181
<ShortcutRenderer
82-
shortcut="Shift+Alt+Enter"
82+
shortcut={shortcuts.appendScreenshot.key}
8383
className="inline-block scale-75 text-xs border border-current bg-transparent py-0 px-1 ml-1"
8484
/>
8585
追加截图
8686
</span>
8787
<span>
8888
<ShortcutRenderer
89-
shortcut="Alt+Enter"
89+
shortcut={shortcuts.takeScreenshot.key}
9090
className="inline-block scale-75 text-xs border border-current bg-transparent py-0 px-1"
9191
/>
9292
新开对话

src/renderer/src/help/FAQ.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BookOpen } from 'lucide-react'
22
import ShortcutRenderer from '@/components/ShortcutRenderer'
3+
import { platformAlt } from '@/lib/utils/env'
34
import { HelpSection } from './components'
45

56
const faqs = [
@@ -8,7 +9,7 @@ const faqs = [
89
answer: (
910
<span>
1011
按下
11-
<ShortcutRenderer shortcut="Alt+Enter" className="text-xs mx-1" />
12+
<ShortcutRenderer shortcut={`${platformAlt}+Enter`} className="text-xs mx-1" />
1213
快捷键即可截取当前屏幕的截图。截图会自动显示在应用中。
1314
</span>
1415
)
@@ -18,7 +19,7 @@ const faqs = [
1819
answer: (
1920
<span>
2021
按下
21-
<ShortcutRenderer shortcut="Alt+Shift+Enter" className="text-xs mx-1" />
22+
<ShortcutRenderer shortcut={`${platformAlt}+Shift+Enter`} className="text-xs mx-1" />
2223
快捷键即可在当前对话中追加截图并生成解题建议。
2324
</span>
2425
)
@@ -45,7 +46,8 @@ const faqs = [
4546
answer: (
4647
<span>
4748
本工具提供了开关,可以开启或关闭鼠标穿透。开启鼠标穿透时,窗口对鼠标隐身,你需要通过快捷键来操作窗口。切换「鼠标穿透」开关的快捷键是{' '}
48-
<ShortcutRenderer shortcut="Alt+M" className="text-xs" /> 。窗口右下角会显示当前状态。
49+
<ShortcutRenderer shortcut={`${platformAlt}+M`} className="text-xs" />{' '}
50+
。窗口右下角会显示当前状态。
4951
</span>
5052
)
5153
}

src/renderer/src/help/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from 'lucide-react'
1111
import { Button } from '@/components/ui/button'
1212
import ShortcutRenderer from '@/components/ShortcutRenderer'
13+
import { platformAlt } from '@/lib/utils/env'
1314
import { HelpSection } from './components'
1415
import { Shortcuts } from './Shortcuts'
1516
import { FAQ } from './FAQ'
@@ -75,7 +76,7 @@ export default function HelpPage() {
7576
<h3 className="font-semibold mb-2">1. 截取屏幕截图</h3>
7677
<p className="text-sm text-gray-700">
7778
当您需要分析某个问题时,按下快捷键{' '}
78-
<ShortcutRenderer shortcut="Alt+Enter" className="text-xs mx-1" />
79+
<ShortcutRenderer shortcut={`${platformAlt}+Enter`} className="text-xs mx-1" />
7980
截取当前屏幕。截图会立即显示在应用中。
8081
</p>
8182
</div>

src/renderer/src/lib/store/shortcuts.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { create } from 'zustand'
22
import { persist } from 'zustand/middleware'
3+
import { isMac, platformAlt } from '../utils/env'
34

45
export type Shortcut = {
56
action: string
@@ -37,23 +38,27 @@ function isPersistedShortcutsState(value: unknown): value is PersistedShortcutsS
3738
const defaultShortcuts: Record<string, Omit<Shortcut, 'defaultKey'>> = {
3839
hideOrShowMainWindow: {
3940
action: 'hideOrShowMainWindow',
40-
key: 'Alt+H',
41+
key: `${platformAlt}+H`,
4142
category: 'Window Management'
4243
},
4344
ignoreOrEnableMouse: {
4445
action: 'ignoreOrEnableMouse',
45-
key: 'Alt+M',
46+
key: `${platformAlt}+M`,
4647
category: 'Window Management'
4748
},
48-
takeScreenshot: { action: 'takeScreenshot', key: 'Alt+Enter', category: 'Screenshot & AI' },
49+
takeScreenshot: {
50+
action: 'takeScreenshot',
51+
key: `${platformAlt}+Enter`,
52+
category: 'Screenshot & AI'
53+
},
4954
appendScreenshot: {
5055
action: 'appendScreenshot',
51-
key: 'Alt+Shift+Enter',
56+
key: `${platformAlt}+Shift+Enter`,
5257
category: 'Screenshot & AI'
5358
},
5459
stopSolutionStream: {
5560
action: 'stopSolutionStream',
56-
key: 'Alt+.',
61+
key: `${platformAlt}+.`,
5762
category: 'Screenshot & AI'
5863
},
5964
pageUp: { action: 'pageUp', key: 'CommandOrControl+J', category: 'Navigation' },
@@ -113,8 +118,8 @@ export const useShortcutsStore = create<ShortcutsStore>()(
113118
}),
114119
{
115120
name: 'interview-coder-shortcuts',
116-
version: 2,
117-
migrate: (state: unknown) => {
121+
version: 3,
122+
migrate: (state: unknown, version: number) => {
118123
if (!isPersistedShortcutsState(state) || !state.shortcuts) return state as ShortcutsStore
119124
// Merge in any new default shortcuts that are missing
120125
const defaults = Object.fromEntries(
@@ -123,13 +128,26 @@ export const useShortcutsStore = create<ShortcutsStore>()(
123128
{ ...shortcut, defaultKey: shortcut.key }
124129
])
125130
)
126-
return {
131+
const merged = {
127132
...state,
128133
shortcuts: {
129134
...defaults,
130135
...state.shortcuts
131136
}
132137
} as ShortcutsStore
138+
139+
// v2→v3: On Windows, migrate Alt shortcuts to CommandOrControl (Ctrl)
140+
if (version < 3 && !isMac) {
141+
for (const [action, shortcut] of Object.entries(merged.shortcuts)) {
142+
merged.shortcuts[action] = {
143+
...shortcut,
144+
key: shortcut.key.replace(/\bAlt\b/g, 'CommandOrControl'),
145+
defaultKey: shortcut.defaultKey.replace(/\bAlt\b/g, 'CommandOrControl')
146+
}
147+
}
148+
}
149+
150+
return merged
133151
}
134152
}
135153
)

src/renderer/src/lib/utils/env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
export const isMac = navigator.userAgent.includes('Mac')
2+
3+
/** Alt on macOS, CommandOrControl (i.e. Ctrl) on Windows/Linux */
4+
export const platformAlt = isMac ? 'Alt' : 'CommandOrControl'

0 commit comments

Comments
 (0)