Fix shape create undos (#199)

This commit is contained in:
Steve Ruiz 2021-10-22 14:49:29 +01:00 committed by GitHub
parent 9aa9a88838
commit f2960033b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 7 deletions

View file

@ -70,8 +70,6 @@ describe('TLDrawState', () => {
const newGroup = newShapes.find((shape) => shape.type === TLDrawShapeType.Group)
console.log(newGroup)
const newChildIds = newShapes
.filter((shape) => shape.type !== TLDrawShapeType.Group)
.map((shape) => shape.id)

View file

@ -1930,6 +1930,16 @@ export class TLDrawState extends StateManager<Data> {
return this.setState(Commands.create(this.state, shapes, bindings))
}
/**
* Patch in a new set of shapes
* @param shapes
* @param bindings
*/
patchCreate = (shapes: TLDrawShape[] = [], bindings: TLDrawBinding[] = []): this => {
if (shapes.length === 0) return this
return this.patchState(Commands.create(this.state, shapes, bindings).after)
}
/**
* Delete one or more shapes.
* @param ids The ids of the shapes to delete.

View file

@ -28,7 +28,7 @@ export class ArrowTool extends BaseTool {
style: { ...currentStyle },
})
this.state.createShapes(newShape)
this.state.patchCreate([newShape])
this.state.startSession(SessionType.Arrow, pagePoint, 'end', true)

View file

@ -34,7 +34,7 @@ export class DrawTool extends BaseTool {
style: { ...currentStyle },
})
this.state.createShapes(newShape)
this.state.patchCreate([newShape])
this.state.startSession(SessionType.Draw, pagePoint, id)

View file

@ -1,5 +1,5 @@
import Vec from '@tldraw/vec'
import { Utils, TLPointerEventHandler, TLKeyboardEventHandler, TLBoundsCorner } from '@tldraw/core'
import { Utils, TLPointerEventHandler, TLBoundsCorner } from '@tldraw/core'
import { Ellipse } from '~shape/shapes'
import { SessionType, TLDrawShapeType } from '~types'
import { BaseTool, Status } from '../BaseTool'
@ -28,7 +28,7 @@ export class EllipseTool extends BaseTool {
style: { ...currentStyle },
})
this.state.createShapes(newShape)
this.state.patchCreate([newShape])
this.state.startSession(
SessionType.TransformSingle,

View file

@ -28,7 +28,7 @@ export class RectangleTool extends BaseTool {
style: { ...currentStyle },
})
this.state.createShapes(newShape)
this.state.patchCreate([newShape])
this.state.startSession(
SessionType.TransformSingle,