svg-layout-designer-react/src/Components/Editor/Shortcuts.ts
Siklos c81a6fe44b
All checks were successful
continuous-integration/drone/push Build is passing
Implement events for external use + Rename interfaces with a I prefix + add some documentation (#26)
Implement events for external use
Rename interfaces with a I prefix
Add some documentation

Co-authored-by: Eric NGUYEN <enguyen@techform.fr>
Reviewed-on: https://git.siklos-chaneru.duckdns.org/Siklos/svg-layout-designer-react/pulls/26
2022-08-12 06:36:14 -04:00

23 lines
702 B
TypeScript

import { Dispatch, SetStateAction } from 'react';
import { IHistoryState } from '../../Interfaces/IHistoryState';
export function onKeyDown(
event: KeyboardEvent,
history: IHistoryState[],
historyCurrentStep: number,
setHistoryCurrentStep: Dispatch<SetStateAction<number>>
): void {
event.preventDefault();
if (event.isComposing || event.keyCode === 229) {
return;
}
if (event.key === 'z' &&
event.ctrlKey &&
historyCurrentStep > 0) {
setHistoryCurrentStep(historyCurrentStep - 1);
} else if (event.key === 'y' &&
event.ctrlKey &&
historyCurrentStep < history.length - 1) {
setHistoryCurrentStep(historyCurrentStep + 1);
}
}