fix(canvas): 防止空格平移误触弹窗按钮

This commit is contained in:
枯木泽
2026-07-18 20:21:18 +08:00
parent 97bb330de1
commit 8bcedfe51b
2 changed files with 9 additions and 2 deletions
@@ -37,11 +37,18 @@ export function useImageEditorViewport(image: ImageSize | null, open: boolean) {
const target = event.target instanceof Element ? event.target : null;
if (target?.closest("input,textarea,[contenteditable='true']")) return;
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
if (document.activeElement instanceof HTMLElement && document.activeElement.matches("button,a,[role='button']")) document.activeElement.blur();
spacePressedRef.current = true;
setSpacePressed(true);
};
const handleKeyUp = (event: KeyboardEvent) => {
if (event.code === "Space") releaseSpace();
if (event.code !== "Space" || !spacePressedRef.current) return;
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
releaseSpace();
};
window.addEventListener("keydown", handleKeyDown, true);
window.addEventListener("keyup", handleKeyUp, true);