Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS to TS : src/simulator/src/hotkey_binder/model/addShortcut.ts #424

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -15,14 +11,46 @@ import { saveOffline, openOffline } from '../../data/project'
import createSaveAsImgPrompt from '../../data/saveImage'
import { createSubCircuitPrompt } from '../../subcircuit'
import { createCombinationalAnalysisPrompt } from '../../combinationalAnalysis'
import { shortcut } from './shortcuts.plugin.js'
import { shortcut } from './shortcuts.plugin'
import logixFunction from '../../data'

export const addShortcut = (keys, action) => {
let callback
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'

interface ShortcutOptions {
type: string
propagate: boolean
target: Document
disable_in_input: boolean
}

export const addShortcut = (keys: string, action: ActionType): void => {
let callback: () => void

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
Expand Down Expand Up @@ -89,12 +117,14 @@ 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,
})
}
}

shortcut.add(keys, callback, options)
}
Loading