diff --git a/src/simulator/src/hotkey_binder/model/addShortcut.js b/src/simulator/src/hotkey_binder/model/addShortcut.ts similarity index 73% rename from src/simulator/src/hotkey_binder/model/addShortcut.js rename to src/simulator/src/hotkey_binder/model/addShortcut.ts index 6233f71e..c5e0b4dd 100644 --- a/src/simulator/src/hotkey_binder/model/addShortcut.js +++ b/src/simulator/src/hotkey_binder/model/addShortcut.ts @@ -1,8 +1,4 @@ -// import { shortcut } from './Shortcuts.plugin'; -// import createSaveAsImgPrompt from '../../data/saveImage'; -//Assign the callback func for the keymap here import { - // createNewCircuitScopeCall, elementDirection, insertLabel, labelDirection, @@ -17,12 +13,42 @@ import { createSubCircuitPrompt } from '../../subcircuit' import { createCombinationalAnalysisPrompt } from '../../combinationalAnalysis' import { shortcut } from './shortcuts.plugin' import logixFunction from '../../data' +import { ShortcutOptions } from './model.types' + +export type ActionType = + | 'New Circuit' + | 'Save Online' + | 'Save Offline' + | 'Download as Image' + | 'Open Offline' + | 'Insert Sub-circuit' + | 'Combinational Analysis' + | 'Direction Up' + | 'Direction Down' + | 'Direction Left' + | 'Direction Right' + | 'Insert Label' + | 'Label Direction Up' + | 'Label Direction Down' + | 'Label Direction Left' + | 'Label Direction Right' + | 'Move Element Up' + | 'Move Element Down' + | 'Move Element Left' + | 'Move Element Right' + | 'Hotkey Preference' + | 'Open Documentation' + +export const addShortcut = ( + keys: string, + action: ActionType, + customOptions?: Partial +): void => { + let callback: (() => void) | (() => Promise) -export const addShortcut = (keys, action) => { - let callback switch (action) { case 'New Circuit': - callback = logixFunction.createNewCircuitScope // TODO: directly call rather than using dom click + callback = logixFunction.createNewCircuitScope break case 'Save Online': callback = save @@ -89,12 +115,15 @@ export const addShortcut = (keys, action) => { break default: callback = () => console.error('No shortcut found..') - break } - shortcut.add(keys, callback, { + + const options: ShortcutOptions = { type: 'keydown', propagate: false, target: document, disable_in_input: true, - }) -} + ...customOptions + } + + shortcut.add(keys, callback, options) +} \ No newline at end of file