agentleFS
lobehublobehub/lobe-editor/.cursor/rules/hotkey-standards.mdc

lobe-editor / rules

Cursor rule180 starsChanged 12 days agoMITView on GitHub

Comprehensive hotkey architecture and management standards for LobeHub Editor

We split this hotkey-standards.mdc into the rules it gives an agent

5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Add the id to HotkeyEnum in src/types/hotkey.ts.

    line 35
  2. Very specific:

    Add a HotkeyItem to HOTKEYS_REGISTRATION in src/const/hotkey.ts:

    line 36
  3. Very specific:

    Default enableHotkey to true and use that exact prop name.

    line 119
  4. Distinctive:

    Never register hotkeys from React components.

    line 120
  5. Distinctive:

    Test enabling and disabling the hotkey.

    line 122

≈ “Common” is an estimate: at least 1 in 5 of the 6,350 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
hotkey-standards.mdc
---
description: Comprehensive hotkey architecture and management standards for LobeHub Editor
---

# Hotkey Management Standards

## Building Blocks

| What                 | Where                                                                        |
| -------------------- | ---------------------------------------------------------------------------- |
| Hotkey ids           | `HotkeyEnum` in [src/types/hotkey.ts](mdc:src/types/hotkey.ts)               |
| Scopes and key names | `HotkeyScopeEnum`, `KeyEnum` in the same file                                |
| Default bindings     | `HOTKEYS_REGISTRATION` in [src/const/hotkey.ts](mdc:src/const/hotkey.ts)     |
| Options + matching   | [src/utils/hotkey/registerHotkey.ts](mdc:src/utils/hotkey/registerHotkey.ts) |
| Kernel API           | `kernel.registerHotkey(id, callback, options)` (returns a cleanup)           |

Current ids: `Bold`, `BulletList`, `CodeInline`, `Italic`, `Link`, `Mention`, `NumberList`,
`PasteAsPlainText`, `Redo`, `Slash`, `Strikethrough`, `Underline`, `Undo`.

```typescript
export type HotkeyOptions = {
  enabled?: boolean; // false: nothing is registered
  preventDefault?: boolean;
  stopImmediatePropagation?: boolean; // declared, currently not applied by registerHotkey
  stopPropagation?: boolean;
};
```

`kernel.registerHotkey` looks the id up in `HOTKEYS_REGISTRATION` (unknown ids are ignored),
returns a no-op when `enabled === false`, and otherwise registers a `KEY_DOWN_COMMAND`
listener at the binding's `priority`.

## Adding a Hotkey

1. Add the id to `HotkeyEnum` in `src/types/hotkey.ts`.
2. Add a `HotkeyItem` to `HOTKEYS_REGISTRATION` in `src/const/hotkey.ts`:

```typescript
{
  id: HotkeyEnum.Bold,
  keys: combineKeys([KeyEnum.Mod, 'b']),
  priority: COMMAND_PRIORITY_LOW,
  scopes: [HotkeyScopeEnum.Format],
},
```

3. Register it from the plugin's registry (next section) behind `enableHotkey`.

## Registering in a Plugin

Hotkeys are registered in the kernel layer, in `plugin/registry.ts` (`code`, `link`,
`link-highlight`, `list`) or `plugin/register.ts` (`common`):

```typescript
import { mergeRegister } from '@lexical/utils';
import { INSERT_UNORDERED_LIST_COMMAND } from '@lexical/list';
import type { LexicalEditor } from 'lexical';

import type { IEditorKernel } from '@/types';
import { HotkeyEnum } from '@/types/hotkey';

export interface ListRegistryOptions {
  enableHotkey?: boolean;
}

export function registerListCommands(
  editor: LexicalEditor,
  kernel: IEditorKernel,
  options?: ListRegistryOptions,
) {
  const { enableHotkey = true } = options || {};

  return mergeRegister(
    kernel.registerHotkey(
      HotkeyEnum.BulletList,
      () => editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined),
      { enabled: enableHotkey, preventDefault: true, stopImmediatePropagation: true },
    ),
    // ...commands and listeners
  );
}
```

Plugin class (`config` is `public` so `onInit` can read it):

```typescript
onInit(editor: LexicalEditor): void {
  this.register(
    registerListCommands(editor, this.kernel, { enableHotkey: this.config?.enableHotkey }),
  );
}
```

React plugin: expose `enableHotkey?: boolean` (default `true`) in `react/type.ts` and pass it
to `editor.registerPlugin(XPlugin, { enableHotkey, ... })`. Plugins with `enableHotkey` today:
`code`, `common`, `link`, `link-highlight`, `list`.

## Configuring Hotkeys as a User

Options are passed per plugin with `Editor.withProps`:

```tsx
import { ReactLinkPlugin, ReactListPlugin } from '@lobehub/editor';
import { Editor } from '@lobehub/editor/react';

<Editor
  plugins={[
    Editor.withProps(ReactLinkPlugin, { enableHotkey: false }),
    Editor.withProps(ReactListPlugin, { enableHotkey: false }),
  ]}
/>;
```

`getHotkeyById(id)` (exported from `@lobehub/editor`) returns a binding, e.g. to show the
shortcut in a toolbar tooltip.

## Rules

1. Default `enableHotkey` to `true` and use that exact prop name.
2. Never register hotkeys from React components; use the kernel registry.
3. New ids need both the `HotkeyEnum` entry and the `HOTKEYS_REGISTRATION` entry.
4. Test enabling and disabling the hotkey.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.