Hotkey

lobehub/lobehub/.agents/skills/hotkey

作者 lobehub6a3eba96b010无许可证83K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库今天更新

Use for keyboard shortcuts, registration, key combinations, scope, conflicts and shortcut tooltips.

AI 生成的概览

指导在 TypeScript 应用中添加快捷键:常量、注册、国际化、Hook 与提示。

功能
该技能提供在 TypeScript 代码库中新增键盘快捷键的分步指南。内容涵盖更新快捷键 id 联合类型、注册默认按键组合与作用域、添加国际化的标题与描述文案、创建并注册 React Hook,以及可选地添加提示浮层。它还列出了关于作用域、分组、冲突和跨平台按键的最佳实践与排错说明。
适用场景
适用于在该代码库中新增、注册或排查键盘快捷键时。也适用于处理按键组合、快捷键作用域、冲突或快捷键提示浮层。
运行要求
不附带脚本,仅为说明文档。它假定存在一个 TypeScript 项目,包含所引用的包与文件、React Hook 以及国际化文案配置。

Adding Keyboard Shortcuts Guide

Steps to Add a New Hotkey

1. Update Hotkey Constant

In packages/types/src/hotkey.ts, add the new id to the HotkeyId union — it's the source of truth HotkeyEnum is typed against:

typescript
export type HotkeyId =  | 'addUserMessage'  // existing...  | 'saveTopic';

2. Register Default Hotkey

In packages/const/src/hotkeys.ts, KeyEnum and combineKeys are already defined locally in this file, so no import is needed — add the entry to HotkeyEnum and to HOTKEYS_REGISTRATION:

typescript
export const HotkeyEnum = {  // existing...  SaveTopic: 'saveTopic',} as const satisfies Record<string, HotkeyId>;
export const HOTKEYS_REGISTRATION: HotkeyRegistration = [  // existing...  {    group: HotkeyGroupEnum.Conversation,    id: HotkeyEnum.SaveTopic,    keys: combineKeys([KeyEnum.Alt, 'n']),    scopes: [HotkeyScopeEnum.Chat],  },];

3. Add i18n Translation

In packages/locales/src/default/hotkey.ts:

typescript
const hotkey: HotkeyI18nTranslations = {  saveTopic: {    desc: '保存当前话题并新建一个话题',    title: '保存话题',  },};

4. Create and Register Hook

In src/hooks/useHotkeys/chatScope.ts:

typescript
export const useSaveTopicHotkey = () => {  const openNewTopicOrSaveTopic = useChatStore((s) => s.openNewTopicOrSaveTopic);  return useHotkeyById(HotkeyEnum.SaveTopic, openNewTopicOrSaveTopic);};
export const useRegisterChatHotkeys = () => {  useSaveTopicHotkey();  // ...other hotkeys};

5. Add Tooltip (Optional)

tsx
const saveTopicHotkey = useUserStore(settingsSelectors.getHotkeyById(HotkeyEnum.SaveTopic));
<Tooltip hotkey={saveTopicHotkey} title={t('saveTopic.title', { ns: 'hotkey' })}>  <Button icon={<SaveOutlined />} onClick={openNewTopicOrSaveTopic} /></Tooltip>;

Best Practices

  1. Scope: Choose global or chat scope based on functionality
  2. Grouping: Place in appropriate group (System/Layout/Conversation)
  3. Conflict check: Ensure no conflict with system/browser shortcuts
  4. Platform: Use KeyEnum.Mod instead of hardcoded Ctrl or Cmd
  5. Clear description: Provide title and description for users

Troubleshooting

  • Not working: Check scope and RegisterHotkeys hook
  • Not in settings: Verify HOTKEYS_REGISTRATION config
  • Conflict: HotkeyInput component shows warnings
  • Page-specific: Ensure correct scope activation

来源与署名

来源:lobehub/lobehub位于.agents/skills/hotkey提交6a3eba9

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架