| title | hotkey - 快捷键 API |
|---|---|
| sidebar_position | 10 |
@types IPublicApiHotkey
@since v1.0.0
绑定快捷键 API,可以自定义项目快捷键使用。
绑定快捷键
/** * 绑定快捷键 * bind hotkey/hotkeys, * @param combos 快捷键,格式如:['command + s'] 、['ctrl + shift + s'] 等 * @param callback 回调函数 * @param action * @returns */ bind( combos: string[] | string, callback: IPublicTypeHotkeyCallback, action?: string, ): IPublicTypeDisposable;
相关 types
hotkey.bind('command+s', (e) => { e.preventDefault(); // command+s 快捷键按下时需要执行的逻辑 });
hotkey.bind(['command+s', 'command+c'], (e) => { e.preventDefault(); // command+s 或者 command+c 快捷键按下时需要执行的逻辑 });
import { hotkey, } from '@alilc/lowcode-engine'; function saveSchema(schema) { // 保存 schema 相关操作 } const saveSampleHotKey = (ctx: IPublicModelPluginContext) => { return { name: 'saveSample', async init() { hotkey.bind('command+s', (e) => { e.preventDefault(); saveSchema(); }); }, }; } saveSampleHotKey.pluginName = 'saveSampleHotKey'; plugins.register(saveSampleHotKey);