MCPcopy
hub / github.com/alibaba/lowcode-engine / Hotkey

Class Hotkey

packages/editor-core/src/hotkey.ts:346–649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344}
345
346export class Hotkey implements IHotKey {
347 callBacks: IPublicTypeHotkeyCallbacks = {};
348
349 private directMap: HotkeyDirectMap = {};
350
351 private sequenceLevels: SequenceLevels = {};
352
353 private resetTimer = 0;
354
355 private ignoreNextKeyup: boolean | string = false;
356
357 private ignoreNextKeypress = false;
358
359 private nextExpectedAction: boolean | string = false;
360
361 private isActivate = true;
362
363 constructor(readonly viewName: string = 'global') {
364 this.mount(window);
365 }
366
367 activate(activate: boolean): void {
368 this.isActivate = activate;
369 }
370
371 mount(window: Window) {
372 const { document } = window;
373 const handleKeyEvent = this.handleKeyEvent.bind(this);
374 document.addEventListener('keypress', handleKeyEvent, false);
375 document.addEventListener('keydown', handleKeyEvent, false);
376 document.addEventListener('keyup', handleKeyEvent, false);
377 return () => {
378 document.removeEventListener('keypress', handleKeyEvent, false);
379 document.removeEventListener('keydown', handleKeyEvent, false);
380 document.removeEventListener('keyup', handleKeyEvent, false);
381 };
382 }
383
384 bind(combos: string[] | string, callback: IPublicTypeHotkeyCallback, action?: string): Hotkey {
385 this.bindMultiple(Array.isArray(combos) ? combos : [combos], callback, action);
386 return this;
387 }
388
389 unbind(combos: string[] | string, callback: IPublicTypeHotkeyCallback, action?: string) {
390 const combinations = Array.isArray(combos) ? combos : [combos];
391
392 combinations.forEach(combination => {
393 const info: KeyInfo = getKeyInfo(combination, action);
394 const { key, modifiers } = info;
395 const idx = this.callBacks[key].findIndex(info => {
396 return isEqual(info.modifiers, modifiers) && info.callback === callback;
397 });
398 if (idx !== -1) {
399 this.callBacks[key].splice(idx, 1);
400 }
401 });
402 }
403

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…