Implement ctrl-z/ctrl-y #16

Merged
Siklos merged 1 commit from dev.ctrlz into dev 2022-08-05 17:29:16 -04:00
2 changed files with 26 additions and 2 deletions

View file

@ -36,11 +36,11 @@ export class SVG extends React.PureComponent<ISVGProps> {
}
componentDidMount(): void {
window.addEventListener('resize', this.resizeViewBox.bind(this));
window.addEventListener('resize', () => this.resizeViewBox());
}
componentWillUnmount(): void {
window.removeEventListener('resize', this.resizeViewBox.bind(this));
window.removeEventListener('resize', () => this.resizeViewBox());
}
render(): JSX.Element {

View file

@ -34,6 +34,30 @@ class Editor extends React.Component<IEditorProps> {
};
}
componentDidMount(): void {
window.addEventListener('keyup', (event) => this.onKeyDown(event));
}
componentWillUnmount(): void {
window.removeEventListener('keyup', (event) => this.onKeyDown(event));
}
public onKeyDown(event: KeyboardEvent): void {
event.preventDefault();
if (event.isComposing || event.keyCode === 229) {
return;
}
if (event.key === 'z' &&
event.ctrlKey &&
this.state.historyCurrentStep > 0) {
this.LoadState(this.state.historyCurrentStep - 1);
} else if (event.key === 'y' &&
event.ctrlKey &&
this.state.historyCurrentStep < this.state.history.length - 1) {
this.LoadState(this.state.historyCurrentStep + 1);
}
}
public getCurrentHistory = (): IHistoryState[] => this.state.history.slice(0, this.state.historyCurrentStep + 1);
public getCurrentHistoryState = (): IHistoryState => this.state.history[this.state.historyCurrentStep];