Skip to content

Commit

Permalink
fix(board): 修复快捷键无法正常工作的问题
Browse files Browse the repository at this point in the history
解决了键盘快捷键在特定条件下不执行的问题。当按下CTRL+SHIFT或CTRL时,快捷键现在将分别触发redo()和undo()函数,前提是canRedo和canUndo返回true。此外,从组件中移除了useDisableScrollBounce钩子,以防止在触摸操作期间发生意外的页面滚动。
  • Loading branch information
YuniqueUnic committed Aug 28, 2024
1 parent c722619 commit 34987cd
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions app/board/[boardId]/_components/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ export const Canvas = ({ boardId }: CanvasProps) => {
});



useDisableScrollBounce();
const history = useHistory();
// const undo = useUndo();
// const redo = useRedo();
const undo = useUndo();
const redo = useRedo();
const canUndo = useCanUndo();
const canRedo = useCanRedo();

Expand Down Expand Up @@ -253,9 +252,6 @@ export const Canvas = ({ boardId }: CanvasProps) => {

}, [canvasState.mode]);




const translateSelectedLayer = useMutation((
{ storage, self },
point: Point
Expand Down Expand Up @@ -289,8 +285,6 @@ export const Canvas = ({ boardId }: CanvasProps) => {
canvasState,
]);



const onResizeHandlePointerDown = useCallback((
corner: Side,
initialBounds: XYWH,) => {
Expand All @@ -310,6 +304,8 @@ export const Canvas = ({ boardId }: CanvasProps) => {
corner
});

history.resume();

}, [history]);

const onWheel = useCallback((e: React.WheelEvent) => {
Expand Down Expand Up @@ -449,6 +445,8 @@ export const Canvas = ({ boardId }: CanvasProps) => {

setCanvasState({ mode: CanvasMode.Translating, current: point });

history.resume();

}, [
setCanvasState,
camera,
Expand Down Expand Up @@ -480,9 +478,14 @@ export const Canvas = ({ boardId }: CanvasProps) => {
{
if (e.ctrlKey || e.metaKey) {
if (e.shiftKey) {
history.redo();
if (canRedo) {
// TODO: Fix bug for the failure of redoing
redo();
}
} else {
history.undo();
if (canUndo) {
undo();
}
}
}
break;
Expand All @@ -492,15 +495,12 @@ export const Canvas = ({ boardId }: CanvasProps) => {
}
}


document.addEventListener("keydown", onKeyDown);

return () => {
document.removeEventListener("keydown", onKeyDown);
};
},
[deleteLayers, history]);

}, [deleteLayers, history]);

return (
<main className="w-full h-full relative bg-neutral-100 touch-none">
Expand All @@ -511,8 +511,10 @@ export const Canvas = ({ boardId }: CanvasProps) => {
setCanvasState={setCanvasState}
canUndo={canUndo}
canRedo={canRedo}
undo={history.undo}
redo={history.redo}
undo={undo}
redo={redo}
// undo={history.undo}
// redo={history.redo}
/>
<SelectionTools
camera={camera}
Expand Down

0 comments on commit 34987cd

Please sign in to comment.