Fix shape create undos (#199)
This commit is contained in:
parent
9aa9a88838
commit
f2960033b0
6 changed files with 15 additions and 7 deletions
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -28,7 +28,7 @@ export class RectangleTool extends BaseTool {
|
|||
style: { ...currentStyle },
|
||||
})
|
||||
|
||||
this.state.createShapes(newShape)
|
||||
this.state.patchCreate([newShape])
|
||||
|
||||
this.state.startSession(
|
||||
SessionType.TransformSingle,
|
||||
|
|
Loading…
Reference in a new issue