[fix] line tool bug with tool locked (#1841)

This PR fixes a bug where tool lock would cause the line tool to not
work properly.

### Change Type

- [x] `patch` — Bug fix

### Test Plan

1. Turn on tool lock.
2. Draw two line shapes

- [x] Unit Tests
This commit is contained in:
Steve Ruiz 2023-09-05 09:33:56 +01:00 committed by GitHub
parent 249bacf50b
commit e7ad05fbf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 44 deletions

View file

@ -209,3 +209,20 @@ describe('When extending the line with the shift-key in tool-lock mode', () => {
expect(handles.length).toBe(3)
})
})
describe('tool lock bug', () => {
it('works as expected when tool lock is on but shift is off', () => {
expect(editor.currentPageShapes.length).toBe(0)
editor
.updateInstanceState({ isToolLocked: true })
.setCurrentTool('line')
.pointerDown(0, 0)
.pointerMove(10, 10)
.pointerUp(10, 10)
.pointerDown(100, 100)
.pointerMove(110, 110)
.pointerUp(100, 100)
.pointerUp(120, 110)
expect(editor.currentPageShapes.length).toBe(2)
})
})

View file

@ -29,12 +29,11 @@ export class Pointing extends StateNode {
const shape = info.shapeId && this.editor.getShape<TLLineShape>(info.shapeId)
if (shape) {
if (shape && inputs.shiftKey) {
this.markId = `creating:${shape.id}`
this.editor.mark(this.markId)
this.shape = shape
if (inputs.shiftKey) {
const handles = this.editor.getShapeHandles(this.shape)
if (!handles) return
@ -82,7 +81,6 @@ export class Pointing extends StateNode {
},
},
])
}
} else {
const id = createShapeId()