Skip to content

refactor: typescript defined addShortcit.ts, model.types.ts and plugins #488

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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,25 +1,26 @@
// import { shortcut } from './Shortcuts.plugin';
// import createSaveAsImgPrompt from '../../data/saveImage';
//Assign the callback func for the keymap here
import {
// createNewCircuitScopeCall,
elementDirection,
insertLabel,
labelDirection,
openHotkey,
moveElement,
openDocumentation,
} from './actions'
import save from '../../data/save'
import { saveOffline, openOffline } from '../../data/project'
import createSaveAsImgPrompt from '../../data/saveImage'
import { createSubCircuitPrompt } from '../../subcircuit'
import { createCombinationalAnalysisPrompt } from '../../combinationalAnalysis'
import { shortcut } from './shortcuts.plugin'
import logixFunction from '../../data'
} from './actions.js'
import save from '../../data/save.js'
import { saveOffline, openOffline } from '../../data/project.js'
import createSaveAsImgPrompt from '../../data/saveImage.js'
import { createSubCircuitPrompt } from '../../subcircuit.js'
import { createCombinationalAnalysisPrompt } from '../../combinationalAnalysis.js'
import { shortcut } from './shortcuts.plugin.js'
import logixFunction from '../../data.js'
import { ActionType, ShortcutOptions } from './model.types.js'

export const addShortcut = (keys, action) => {
let callback
// Add space after comment as per linter rule
// Assign the callback func for the keymap here

export default function addShortcut(keys: string, action: ActionType): void {
let callback: () => void = () => console.error('No shortcut found..')

switch (action) {
case 'New Circuit':
callback = logixFunction.createNewCircuitScope // TODO: directly call rather than using dom click
Expand Down Expand Up @@ -87,14 +88,14 @@ export const addShortcut = (keys, action) => {
case 'Open Documentation':
callback = openDocumentation
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)
}
24 changes: 24 additions & 0 deletions src/simulator/src/hotkey_binder/model/model.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
//This file holds the interfaces required for src/simulator/src/hotkey_binder/model
//to be continued for storing interfaces of the parent folder

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 interface ShortcutOptions {
type?: string
propagate?: boolean
Expand Down
Loading