Skip to content

Commit

Permalink
fix: undo redo mouseonpane check fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MXerFix committed Sep 30, 2024
1 parent 59c0f06 commit 775eed9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions frontend/src/contexts/undoRedoContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function UndoRedoProvider({ children }: { children: React.ReactNode }) {
const [past, setPast] = useState<HistoryItem[][]>(flows.map(() => []))
const [future, setFuture] = useState<HistoryItem[][]>(flows.map(() => []))
const [tabIndex, setTabIndex] = useState(flows.findIndex((f) => f.name === tab))
const [disableCopyPaste, setDisableCopyPaste] = useState(false)

useEffect(() => {
// whenever the flows variable changes, we need to add one array to the past and future states
Expand Down Expand Up @@ -155,12 +156,12 @@ export function UndoRedoProvider({ children }: { children: React.ReactNode }) {
}

const keyDownHandler = (event: KeyboardEvent) => {
if (event.key === "z" && (event.ctrlKey || event.metaKey) && event.shiftKey) {
if (event.key === "z" && (event.ctrlKey || event.metaKey) && event.shiftKey && !disableCopyPaste) {
redo()
} else if (event.key === "y" && (event.ctrlKey || event.metaKey)) {
} else if (event.key === "y" && (event.ctrlKey || event.metaKey) && !disableCopyPaste) {
event.preventDefault() // prevent the default action
redo()
} else if (event.key === "z" && (event.ctrlKey || event.metaKey)) {
} else if (event.key === "z" && (event.ctrlKey || event.metaKey) && !disableCopyPaste) {
undo()
}
}
Expand All @@ -170,17 +171,18 @@ export function UndoRedoProvider({ children }: { children: React.ReactNode }) {
return () => {
document.removeEventListener("keydown", keyDownHandler)
}
}, [undo, redo])
}, [undo, redo, disableCopyPaste])

const { reactFlowInstance } = useContext(flowContext)
const [copiedSelection, setCopiedSelection] = useState<OnSelectionChangeParams | null>(null)
const [disableCopyPaste, setDisableCopyPaste] = useState(false)

useEffect(() => {
console.log(modalsOpened)
if (modalsOpened === 0) {
setDisableCopyPaste(false)
} else if (modalsOpened > 0) {
setDisableCopyPaste(true)
console.log(true)
}
}, [modalsOpened])

Expand Down

0 comments on commit 775eed9

Please sign in to comment.