mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): add checks for undo/redo actions
This commit is contained in:
parent
7f78fe7a36
commit
dbfaa07e03
@ -66,6 +66,8 @@ export const Flow = memo(() => {
|
|||||||
const nodes = useAppSelector((s) => s.nodes.present.nodes);
|
const nodes = useAppSelector((s) => s.nodes.present.nodes);
|
||||||
const edges = useAppSelector((s) => s.nodes.present.edges);
|
const edges = useAppSelector((s) => s.nodes.present.edges);
|
||||||
const viewport = useStore($viewport);
|
const viewport = useStore($viewport);
|
||||||
|
const mayUndo = useAppSelector((s) => s.nodes.past.length > 0);
|
||||||
|
const mayRedo = useAppSelector((s) => s.nodes.future.length > 0);
|
||||||
const shouldSnapToGrid = useAppSelector((s) => s.workflowSettings.shouldSnapToGrid);
|
const shouldSnapToGrid = useAppSelector((s) => s.workflowSettings.shouldSnapToGrid);
|
||||||
const selectionMode = useAppSelector((s) => s.workflowSettings.selectionMode);
|
const selectionMode = useAppSelector((s) => s.workflowSettings.selectionMode);
|
||||||
const { onConnectStart, onConnect, onConnectEnd } = useConnection();
|
const { onConnectStart, onConnect, onConnectEnd } = useConnection();
|
||||||
@ -192,13 +194,13 @@ export const Flow = memo(() => {
|
|||||||
const { copySelection, pasteSelection } = useCopyPaste();
|
const { copySelection, pasteSelection } = useCopyPaste();
|
||||||
|
|
||||||
useHotkeys(['Ctrl+c', 'Meta+c'], (e) => {
|
useHotkeys(['Ctrl+c', 'Meta+c'], (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
copySelection();
|
copySelection();
|
||||||
});
|
});
|
||||||
|
|
||||||
useHotkeys(['Ctrl+a', 'Meta+a'], (e) => {
|
useHotkeys(['Ctrl+a', 'Meta+a'], (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
dispatch(selectedAll());
|
dispatch(selectedAll());
|
||||||
});
|
});
|
||||||
|
|
||||||
useHotkeys(['Ctrl+v', 'Meta+v'], (e) => {
|
useHotkeys(['Ctrl+v', 'Meta+v'], (e) => {
|
||||||
@ -222,6 +224,20 @@ export const Flow = memo(() => {
|
|||||||
[dispatch]
|
[dispatch]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const onUndoHotkey = useCallback(() => {
|
||||||
|
if (mayUndo) {
|
||||||
|
dispatch(undo());
|
||||||
|
}
|
||||||
|
}, [dispatch, mayUndo]);
|
||||||
|
useHotkeys(['meta+z', 'ctrl+z'], onUndoHotkey);
|
||||||
|
|
||||||
|
const onRedoHotkey = useCallback(() => {
|
||||||
|
if (mayRedo) {
|
||||||
|
dispatch(redo());
|
||||||
|
}
|
||||||
|
}, [dispatch, mayRedo]);
|
||||||
|
useHotkeys(['meta+shift+z', 'ctrl+shift+z'], onRedoHotkey);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactFlow
|
<ReactFlow
|
||||||
id="workflow-editor"
|
id="workflow-editor"
|
||||||
|
Loading…
Reference in New Issue
Block a user