From 54b66246d666d34912cf466b3192c7ddf143177c Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Mon, 18 Jul 2022 18:01:15 +0100 Subject: [PATCH] Fix flips (#829) --- apps/www/components/IFrameWarning.tsx | 2 -- .../commands/flipShapes/flipShapes.spec.ts | 19 +++++++++++++++++-- .../state/commands/flipShapes/flipShapes.ts | 8 ++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/www/components/IFrameWarning.tsx b/apps/www/components/IFrameWarning.tsx index cb0da33fc..31802c53d 100644 --- a/apps/www/components/IFrameWarning.tsx +++ b/apps/www/components/IFrameWarning.tsx @@ -34,8 +34,6 @@ export default function IFrameWarning({ url = 'https://tldraw.com' }: { url?: st } document.execCommand('copy') } catch (err) { - console.log('nope') - null // Could not copy to clipboard } finally { document.body.removeChild(textarea) diff --git a/packages/tldraw/src/state/commands/flipShapes/flipShapes.spec.ts b/packages/tldraw/src/state/commands/flipShapes/flipShapes.spec.ts index db38de9e6..bf2d9aa2b 100644 --- a/packages/tldraw/src/state/commands/flipShapes/flipShapes.spec.ts +++ b/packages/tldraw/src/state/commands/flipShapes/flipShapes.spec.ts @@ -19,31 +19,46 @@ describe('Flip command', () => { }) it('does, undoes and redoes command', () => { - app.select('rect1', 'rect2') - app.flipHorizontal() + expect(app.getShape('rect1').point).toStrictEqual([0, 0]) + expect(app.getShape('rect2').point).toStrictEqual([100, 100]) + + app.select('rect1', 'rect2').flipHorizontal() expect(app.getShape('rect1').point).toStrictEqual([100, 0]) + expect(app.getShape('rect2').point).toStrictEqual([0, 100]) app.undo() expect(app.getShape('rect1').point).toStrictEqual([0, 0]) + expect(app.getShape('rect2').point).toStrictEqual([100, 100]) app.redo() expect(app.getShape('rect1').point).toStrictEqual([100, 0]) + expect(app.getShape('rect2').point).toStrictEqual([0, 100]) }) it('flips horizontally', () => { app.select('rect1', 'rect2') + + expect(app.getShape('rect1').point).toStrictEqual([0, 0]) + expect(app.getShape('rect2').point).toStrictEqual([100, 100]) + app.flipHorizontal() expect(app.getShape('rect1').point).toStrictEqual([100, 0]) + expect(app.getShape('rect2').point).toStrictEqual([0, 100]) }) it('flips vertically', () => { app.select('rect1', 'rect2') + + expect(app.getShape('rect1').point).toStrictEqual([0, 0]) + expect(app.getShape('rect2').point).toStrictEqual([100, 100]) + app.flipVertical() expect(app.getShape('rect1').point).toStrictEqual([0, 100]) + expect(app.getShape('rect2').point).toStrictEqual([100, 0]) }) }) diff --git a/packages/tldraw/src/state/commands/flipShapes/flipShapes.ts b/packages/tldraw/src/state/commands/flipShapes/flipShapes.ts index 56f9150b8..ee6e085d1 100644 --- a/packages/tldraw/src/state/commands/flipShapes/flipShapes.ts +++ b/packages/tldraw/src/state/commands/flipShapes/flipShapes.ts @@ -5,9 +5,13 @@ import type { TldrawApp } from '../../internal' import { TLDR } from '~state/TLDR' export function flipShapes(app: TldrawApp, ids: string[], type: FlipType): TldrawCommand { - const { selectedIds, currentPageId, shapes } = app + const { + selectedIds, + currentPageId, + page: { shapes }, + } = app - const boundsForShapes = shapes.map((shape) => TLDR.getBounds(shape)) + const boundsForShapes = ids.map((id) => TLDR.getBounds(shapes[id])) const commonBounds = Utils.getCommonBounds(boundsForShapes)