Skip to content

Commit

Permalink
fix: Add a branch to avoid null shape range
Browse files Browse the repository at this point in the history
  • Loading branch information
miyanokomiya committed Oct 31, 2023
1 parent 9a2faf9 commit c133b63
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/composables/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export function useCanvas(
const { scale, viewOrigin } = viewState.state;
const setScale = useCallback(
(val: number) => {
// For safety
if (isNaN(val)) return;
viewState.setState((state) => ({ scale: val, viewOrigin: state.viewOrigin }));
},
[viewState.setState],
Expand Down
4 changes: 3 additions & 1 deletion src/composables/states/appCanvas/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ export function handleCommonShortcut(
case "!":
case "Home": {
const shapeComposite = ctx.getShapeComposite();
ctx.setViewport(geometry.getWrapperRect(shapeComposite.shapes.map((s) => shapeComposite.getWrapperRect(s))), 80);
const rects = shapeComposite.shapes.map((s) => shapeComposite.getWrapperRect(s));
if (rects.length === 0) return;
ctx.setViewport(geometry.getWrapperRect(rects), 80);
return;
}
}
Expand Down

0 comments on commit c133b63

Please sign in to comment.