From 5dc1436d808ce40013bda693cf6b754a3d49771c Mon Sep 17 00:00:00 2001 From: Lu Wilson Date: Tue, 19 Sep 2023 13:16:38 +0100 Subject: [PATCH] Fix lines being draggable via their background (#1920) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1914 ### Change Type - [x] `patch` — Bug fix ### Test Plan 1. Draw a line shape at a 45 degree angle. 2. Select the line. 3. Click and drag the empty space next to the line. 4. It should select the canvas. - [x] Unit Tests - [ ] End to end tests ### Release Notes - None - unreleased bug --- packages/tldraw/api-report.md | 2 ++ .../src/lib/shapes/line/LineShapeUtil.tsx | 1 + .../tldraw/src/test/selection-omnibus.test.ts | 32 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/packages/tldraw/api-report.md b/packages/tldraw/api-report.md index 9129379e1..5cafdda87 100644 --- a/packages/tldraw/api-report.md +++ b/packages/tldraw/api-report.md @@ -786,6 +786,8 @@ export class LineShapeUtil extends ShapeUtil { // (undocumented) hideRotateHandle: () => boolean; // (undocumented) + hideSelectionBoundsBg: () => boolean; + // (undocumented) hideSelectionBoundsFg: () => boolean; // (undocumented) indicator(shape: TLLineShape): JSX.Element; diff --git a/packages/tldraw/src/lib/shapes/line/LineShapeUtil.tsx b/packages/tldraw/src/lib/shapes/line/LineShapeUtil.tsx index 370235c05..01a394d23 100644 --- a/packages/tldraw/src/lib/shapes/line/LineShapeUtil.tsx +++ b/packages/tldraw/src/lib/shapes/line/LineShapeUtil.tsx @@ -41,6 +41,7 @@ export class LineShapeUtil extends ShapeUtil { override hideResizeHandles = () => true override hideRotateHandle = () => true override hideSelectionBoundsFg = () => true + override hideSelectionBoundsBg = () => true override getDefaultProps(): TLLineShape['props'] { return { diff --git a/packages/tldraw/src/test/selection-omnibus.test.ts b/packages/tldraw/src/test/selection-omnibus.test.ts index be737e261..f2adffecc 100644 --- a/packages/tldraw/src/test/selection-omnibus.test.ts +++ b/packages/tldraw/src/test/selection-omnibus.test.ts @@ -312,6 +312,38 @@ describe('when shape is hollow', () => { editor.expectToBeIn('select.pointing_canvas') editor.pointerUp() }) + + it('does not drag line shape', () => { + editor + .selectAll() + .deleteShapes(editor.selectedShapeIds) + .setCurrentTool('line') + .pointerMove(500, 500) + .pointerDown() + .pointerMove(600, 600) + .pointerUp() + .selectAll() + .setCurrentTool('select') + + expect(editor.selectedShapeIds.length).toBe(1) + + // Not inside of the shape but inside of the selection bounds + editor.pointerMove(510, 590) + expect(editor.hoveredShapeId).toBe(null) + + // Line shapes have `hideSelectionBoundsBg` set to true + editor.pointerDown() + editor.expectToBeIn('select.pointing_canvas') + + editor.selectAll() + editor.rotateSelection(Math.PI) + editor.setCurrentTool('select') + editor.pointerMove(590, 510) + + editor.pointerDown() + editor.expectToBeIn('select.pointing_canvas') + editor.pointerUp() + }) }) describe('when shape is a frame', () => {