Add Undo/Redo to contextmenu + add separator between categories

This commit is contained in:
Eric NGUYEN 2022-10-04 17:22:28 +02:00
parent cf3c966170
commit 1086bf58a1
2 changed files with 84 additions and 19 deletions

View file

@ -27,8 +27,37 @@ function InitActions(
configuration: IConfiguration,
history: IHistoryState[],
historyCurrentStep: number,
setNewHistory: (newHistory: IHistoryState[]) => void
setNewHistory: (newHistory: IHistoryState[]) => void,
setHistoryCurrentStep: Dispatch<SetStateAction<number>>
): void {
menuActions.set(
'',
[
{
text: 'Undo',
title: 'Undo last action',
shortcut: '<kbd>Ctrl</kbd>+<kbd>Z</kbd>',
action: () => {
if (historyCurrentStep <= 0) {
return;
}
setHistoryCurrentStep(historyCurrentStep - 1);
}
},
{
text: 'Redo',
title: 'Redo last action',
shortcut: '<kbd>Ctrl</kbd>+<kbd>Y</kbd>',
action: () => {
if (historyCurrentStep >= history.length - 1) {
return;
}
setHistoryCurrentStep(historyCurrentStep + 1);
}
}
]
);
menuActions.set(
'elements-sidebar-row',
[{
@ -46,6 +75,7 @@ function InitActions(
}
}]
);
menuActions.set(
'symbols-sidebar-row',
[{
@ -237,7 +267,8 @@ export function Editor(props: IEditorProps): JSX.Element {
props.configuration,
history,
historyCurrentStep,
setNewHistory
setNewHistory,
setHistoryCurrentStep
);
// Render