Fix shape create undos (#199)

pull/200/head
Steve Ruiz 2021-10-22 14:49:29 +01:00 zatwierdzone przez GitHub
rodzic 9aa9a88838
commit f2960033b0
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
6 zmienionych plików z 15 dodań i 7 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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.

Wyświetl plik

@ -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)

Wyświetl plik

@ -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)

Wyświetl plik

@ -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,

Wyświetl plik

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