kopia lustrzana https://github.com/Tldraw/Tldraw
Fix bug on arrow
rodzic
3f5f613e09
commit
ac555cd6c6
|
@ -169,6 +169,30 @@ describe('When creating with an arrow session', () => {
|
||||||
expect(tlstate.getShape('arrow1')).toBe(undefined)
|
expect(tlstate.getShape('arrow1')).toBe(undefined)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("Doesn't corrupt a shape after undoing", () => {
|
||||||
|
const tlstate = new TLDrawState()
|
||||||
|
.createShapes(
|
||||||
|
{ type: TLDrawShapeType.Rectangle, id: 'rect1', point: [200, 200], size: [200, 200] },
|
||||||
|
{ type: TLDrawShapeType.Rectangle, id: 'rect2', point: [400, 200], size: [200, 200] },
|
||||||
|
{ type: TLDrawShapeType.Arrow, id: 'arrow1', point: [450, 250] }
|
||||||
|
)
|
||||||
|
.select('arrow1')
|
||||||
|
.startSession(SessionType.Arrow, [250, 250], 'start', true)
|
||||||
|
.updateSession([55, 45])
|
||||||
|
.completeSession()
|
||||||
|
|
||||||
|
expect(tlstate.bindings.length).toBe(2)
|
||||||
|
|
||||||
|
tlstate
|
||||||
|
.undo()
|
||||||
|
.select('rect1')
|
||||||
|
.startSession(SessionType.Translate, [250, 250])
|
||||||
|
.updateSession([275, 275])
|
||||||
|
.completeSession()
|
||||||
|
|
||||||
|
expect(tlstate.bindings.length).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
it('Creates a start binding if possible', () => {
|
it('Creates a start binding if possible', () => {
|
||||||
const tlstate = new TLDrawState()
|
const tlstate = new TLDrawState()
|
||||||
.createShapes(
|
.createShapes(
|
||||||
|
|
|
@ -345,12 +345,12 @@ export class ArrowSession implements Session {
|
||||||
|
|
||||||
const afterBindings: Partial<Record<string, TLDrawBinding>> = {}
|
const afterBindings: Partial<Record<string, TLDrawBinding>> = {}
|
||||||
|
|
||||||
const afterShape = page.shapes[initialShape.id] as ArrowShape
|
let afterShape = page.shapes[initialShape.id] as ArrowShape
|
||||||
|
|
||||||
const currentBindingId = afterShape.handles[handleId].bindingId
|
const currentBindingId = afterShape.handles[handleId].bindingId
|
||||||
|
|
||||||
if (initialBinding) {
|
if (initialBinding) {
|
||||||
beforeBindings[initialBinding.id] = initialBinding
|
beforeBindings[initialBinding.id] = this.isCreate ? undefined : initialBinding
|
||||||
afterBindings[initialBinding.id] = undefined
|
afterBindings[initialBinding.id] = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,6 +364,8 @@ export class ArrowSession implements Session {
|
||||||
afterBindings[newStartBindingId] = page.bindings[newStartBindingId]
|
afterBindings[newStartBindingId] = page.bindings[newStartBindingId]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
afterShape = TLDR.onSessionComplete(afterShape)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: 'arrow',
|
id: 'arrow',
|
||||||
before: {
|
before: {
|
||||||
|
@ -373,7 +375,7 @@ export class ArrowSession implements Session {
|
||||||
shapes: {
|
shapes: {
|
||||||
[initialShape.id]: this.isCreate ? undefined : initialShape,
|
[initialShape.id]: this.isCreate ? undefined : initialShape,
|
||||||
},
|
},
|
||||||
bindings: this.isCreate ? {} : beforeBindings,
|
bindings: beforeBindings,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
pageStates: {
|
pageStates: {
|
||||||
|
@ -391,7 +393,7 @@ export class ArrowSession implements Session {
|
||||||
pages: {
|
pages: {
|
||||||
[data.appState.currentPageId]: {
|
[data.appState.currentPageId]: {
|
||||||
shapes: {
|
shapes: {
|
||||||
[initialShape.id]: TLDR.onSessionComplete(afterShape),
|
[initialShape.id]: afterShape,
|
||||||
},
|
},
|
||||||
bindings: afterBindings,
|
bindings: afterBindings,
|
||||||
},
|
},
|
||||||
|
|
|
@ -213,10 +213,10 @@ export class TLDrawState extends StateManager<Data> {
|
||||||
|
|
||||||
const toUtils = TLDR.getShapeUtils(toShape)
|
const toUtils = TLDR.getShapeUtils(toShape)
|
||||||
|
|
||||||
// We only need to update the binding's "from" shape
|
const fromUtils = TLDR.getShapeUtils(fromShape)
|
||||||
const util = TLDR.getShapeUtils(fromShape)
|
|
||||||
|
|
||||||
const fromDelta = util.onBindingChange(
|
// We only need to update the binding's "from" shape
|
||||||
|
const fromDelta = fromUtils.onBindingChange(
|
||||||
fromShape,
|
fromShape,
|
||||||
binding,
|
binding,
|
||||||
toShape,
|
toShape,
|
||||||
|
|
Ładowanie…
Reference in New Issue