[fix] brush selection on groups (#335)

* select groups rather than grouped shapes

* Adds test
This commit is contained in:
Steve Ruiz 2021-11-21 12:40:17 +00:00 committed by GitHub
parent ec6d824b88
commit adb680f8cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 7 deletions

View file

@ -49,7 +49,7 @@
"@radix-ui/react-radio-group": "^0.1.1",
"@radix-ui/react-tooltip": "^0.1.1",
"@stitches/react": "^1.2.5",
"@tldraw/core": "^1.1.0",
"@tldraw/core": "^1.1.1",
"@tldraw/intersect": "latest",
"@tldraw/vec": "latest",
"perfect-freehand": "^1.0.16",

View file

@ -51,8 +51,6 @@ describe('Brush session', () => {
it('when command is held, require the entire shape to be selected', () => {
const app = new TldrawTestApp()
.loadDocument(mockDocument)
.selectNone()
.loadDocument(mockDocument)
.selectNone()
.movePointer([-10, -10])
@ -62,4 +60,17 @@ describe('Brush session', () => {
expect(app.selectedIds.length).toBe(0)
})
it('selects groups rather than grouped shapes', () => {
const app = new TldrawTestApp()
.loadDocument(mockDocument)
.selectAll()
.group()
.movePointer([-10, -10])
.startSession(SessionType.Brush)
.movePointer({ x: 100, y: 100 })
.stopPointing()
expect(app.selectedIds.length).toBe(1)
})
})

View file

@ -15,6 +15,7 @@ export class BrushSession extends BaseSession {
constructor(app: TldrawApp) {
super(app)
const { currentPageId } = app
this.initialSelectedIds = new Set(this.app.selectedIds)
this.shapesToTest = this.app.shapes
.filter(
@ -22,7 +23,7 @@ export class BrushSession extends BaseSession {
!(
shape.isLocked ||
shape.isHidden ||
shape.children !== undefined ||
shape.parentId !== currentPageId ||
this.initialSelectedIds.has(shape.id) ||
this.initialSelectedIds.has(shape.parentId)
)
@ -52,8 +53,6 @@ export class BrushSession extends BaseSession {
const selectedIds = new Set(initialSelectedIds)
shapesToTest.forEach(({ id, selectId }) => {
if (selectedIds.has(id)) return
const { metaKey } = this.app
const shape = this.app.getShape(id)

View file

@ -8,7 +8,8 @@
"rootDir": "src",
"baseUrl": "src",
"paths": {
"~*": ["./*"]
"~*": ["./*"],
"@tldraw/core": ["../core"]
}
},
"typedocOptions": {