Fix bug on arrow

pull/163/head
Steve Ruiz 2021-10-16 23:17:41 +01:00
rodzic 3f5f613e09
commit ac555cd6c6
3 zmienionych plików z 33 dodań i 7 usunięć

Wyświetl plik

@ -169,6 +169,30 @@ describe('When creating with an arrow session', () => {
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', () => {
const tlstate = new TLDrawState()
.createShapes(

Wyświetl plik

@ -345,12 +345,12 @@ export class ArrowSession implements Session {
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
if (initialBinding) {
beforeBindings[initialBinding.id] = initialBinding
beforeBindings[initialBinding.id] = this.isCreate ? undefined : initialBinding
afterBindings[initialBinding.id] = undefined
}
@ -364,6 +364,8 @@ export class ArrowSession implements Session {
afterBindings[newStartBindingId] = page.bindings[newStartBindingId]
}
afterShape = TLDR.onSessionComplete(afterShape)
return {
id: 'arrow',
before: {
@ -373,7 +375,7 @@ export class ArrowSession implements Session {
shapes: {
[initialShape.id]: this.isCreate ? undefined : initialShape,
},
bindings: this.isCreate ? {} : beforeBindings,
bindings: beforeBindings,
},
},
pageStates: {
@ -391,7 +393,7 @@ export class ArrowSession implements Session {
pages: {
[data.appState.currentPageId]: {
shapes: {
[initialShape.id]: TLDR.onSessionComplete(afterShape),
[initialShape.id]: afterShape,
},
bindings: afterBindings,
},

Wyświetl plik

@ -213,10 +213,10 @@ export class TLDrawState extends StateManager<Data> {
const toUtils = TLDR.getShapeUtils(toShape)
// We only need to update the binding's "from" shape
const util = TLDR.getShapeUtils(fromShape)
const fromUtils = TLDR.getShapeUtils(fromShape)
const fromDelta = util.onBindingChange(
// We only need to update the binding's "from" shape
const fromDelta = fromUtils.onBindingChange(
fromShape,
binding,
toShape,