PluginBench
Skill
Pass
Audit score 90

hotkey

lobehub/lobe-chat

Add or edit LobeHub keyboard shortcuts with proper scoping, conflict detection, and i18n support.

What is hotkey?

This skill enables adding and managing keyboard shortcuts in LobeHub Chat. Use it when you need to create new hotkeys, register them with scope and conflict handling, add translations, and wire them to UI actions via hooks.

  • Define hotkey constants in HotkeyEnum and register them with key combinations and scopes
  • Create and register hooks (useHotkeyById, useRegisterChatHotkeys) to bind hotkeys to chat actions
  • Add i18n translations for hotkey titles and descriptions across locales
  • Configure hotkey scope (global vs. chat-specific) and detect conflicts with system shortcuts
  • Integrate hotkeys into UI components with tooltip display using the Tooltip component
  • Support platform-agnostic key combinations using Key.Mod for Cmd/Ctrl detection

How to install hotkey

npx skills add https://github.com/lobehub/lobe-chat --skill hotkey
Prerequisites
  • Access to LobeHub Chat source code (src/ directory)
  • Familiarity with TypeScript and React hooks
  • Understanding of LobeHub's i18n structure and locale files
  • Knowledge of the @lobehub/ui KeyMapEnum and combineKeys utility
Claude Code
Cursor
Windsurf
Cline

How to use hotkey

  1. 1.Define the new hotkey in src/types/hotkey.ts by adding an entry to HotkeyEnum
  2. 2.Register the hotkey in src/const/hotkeys.ts with key combination, group, and scope
  3. 3.Add i18n translations in src/locales/default/hotkey.ts for title and description
  4. 4.Create a custom hook in src/hooks/useHotkeys/ that calls useHotkeyById with your action
  5. 5.Register the hook in useRegisterChatHotkeys or appropriate scope hook
  6. 6.Optionally add a Tooltip to UI components displaying the hotkey using useUserStore selectors

Use cases

Good for
  • Adding a new keyboard shortcut like Cmd/Ctrl+Shift+Backspace to clear chat messages
  • Creating chat-scoped hotkeys that only activate in conversation context
  • Implementing hotkey settings UI that displays available shortcuts and detects conflicts
  • Adding multilingual hotkey descriptions for international users
  • Binding complex key combinations (modifier + multiple keys) to specific chat actions
Who it's for
  • LobeHub Chat developers extending keyboard navigation
  • Contributors adding new chat features with hotkey support
  • Developers implementing accessibility features via keyboard shortcuts
  • Teams managing hotkey conflicts across a large codebase

hotkey FAQ

What's the difference between global and chat scope?

Global scope hotkeys work everywhere in the app; chat scope hotkeys only activate when in a conversation. Choose based on whether the action is chat-specific or app-wide.

How do I handle platform differences (Cmd vs Ctrl)?

Use Key.Mod from @lobehub/ui instead of hardcoding Ctrl or Cmd. The combineKeys utility automatically maps to the correct key for each platform.

What should I do if my hotkey conflicts with a system shortcut?

Check the HotkeyInput component warnings during development. Verify the conflict list and choose an alternative key combination that doesn't clash with browser or OS shortcuts.

How do I make hotkey descriptions appear in multiple languages?

Add translations to src/locales/default/hotkey.ts with the same key structure. The i18n system will automatically load the correct language based on user settings.

Why isn't my hotkey working after registration?

Verify that the scope is activated (check RegisterHotkeys hook is called), the HotkeyEnum constant exists, and the key combination is registered in HOTKEYS_REGISTRATION.

Full instructions (SKILL.md)

Source of truth, from lobehub/lobe-chat.


name: hotkey description: 'Add or edit LobeHub keyboard shortcuts. Use for HotkeyEnum, HOTKEYS_REGISTRATION, combineKeys, useHotkeyById, tooltip hotkeys, shortcut scope, conflicts, or Cmd/Ctrl key combos.' user-invocable: false

Adding Keyboard Shortcuts Guide

Steps to Add a New Hotkey

1. Update Hotkey Constant

In src/types/hotkey.ts:

export const HotkeyEnum = {
  // existing...
  ClearChat: 'clearChat', // Add new
} as const;

2. Register Default Hotkey

In src/const/hotkeys.ts:

import { KeyMapEnum as Key, combineKeys } from '@lobehub/ui';

export const HOTKEYS_REGISTRATION: HotkeyRegistration = [
  {
    group: HotkeyGroupEnum.Conversation,
    id: HotkeyEnum.ClearChat,
    keys: combineKeys([Key.Mod, Key.Shift, Key.Backspace]),
    scopes: [HotkeyScopeEnum.Chat],
  },
];

3. Add i18n Translation

In src/locales/default/hotkey.ts:

const hotkey: HotkeyI18nTranslations = {
  clearChat: {
    desc: '清空当前会话的所有消息记录',
    title: '清空聊天记录',
  },
};

4. Create and Register Hook

In src/hooks/useHotkeys/chatScope.ts:

export const useClearChatHotkey = () => {
  const clearMessages = useChatStore((s) => s.clearMessages);
  return useHotkeyById(HotkeyEnum.ClearChat, clearMessages);
};

export const useRegisterChatHotkeys = () => {
  useClearChatHotkey();
  // ...other hotkeys
};

5. Add Tooltip (Optional)

const clearChatHotkey = useUserStore(settingsSelectors.getHotkeyById(HotkeyEnum.ClearChat));

<Tooltip hotkey={clearChatHotkey} title={t('clearChat.title', { ns: 'hotkey' })}>
  <Button icon={<DeleteOutlined />} onClick={clearMessages} />
</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 Key.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