Skip to content

Commit

Permalink
[bugfix] Cleanup input state after middle-click-to-pan (#3792)
Browse files Browse the repository at this point in the history
closes #3013 
closes #3733

This fixes a bug wherein the `inputs.isPanning` state was not being
unset correctly after a middle-click-to-pan gesture with a mouse.

### Change Type

<!-- ❗ Please select a 'Scope' label ❗️ -->

- [x] `sdk` — Changes the tldraw SDK
- [ ] `dotcom` — Changes the tldraw.com web app
- [ ] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff

<!-- ❗ Please select a 'Type' label ❗️ -->

- [x] `bugfix` — Bug fix
- [ ] `feature` — New feature
- [ ] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `galaxy brain` — Architectural changes
- [ ] `tests` — Changes to any test code
- [ ] `tools` — Changes to infrastructure, CI, internal scripts,
debugging tools, etc.
- [ ] `dunno` — I don't know


### Test Plan

1. Add a step-by-step description of how to test your PR here.
2.

- [ ] Unit Tests
- [ ] End to end tests

### Release Notes

- Add a brief release note for your PR here.
  • Loading branch information
ds300 committed May 21, 2024
1 parent ec128da commit 1452978
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/editor/src/lib/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8645,6 +8645,9 @@ export class Editor extends EventEmitter<TLEventMap> {
}

if (inputs.isPanning) {
if (!inputs.keys.has('Space')) {
inputs.isPanning = false
}
const slideDirection = this.inputs.pointerVelocity
const slideSpeed = Math.min(2, slideDirection.len())

Expand Down
30 changes: 30 additions & 0 deletions packages/tldraw/src/test/Editor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -646,3 +646,33 @@ describe('when the user prefers light UI', () => {
expect(editor.user.getIsDarkMode()).toBe(false)
})
})

describe('middle-click panning', () => {
it('clears the isPanning state on mouse up', () => {
editor.pointerDown(0, 0, {
// middle mouse button
button: 1,
})
editor.pointerMove(100, 100)
expect(editor.inputs.isPanning).toBe(true)
editor.pointerUp(100, 100)
expect(editor.inputs.isPanning).toBe(false)
})

it('does not clear thee isPanning state if the space bar is down', () => {
editor.pointerDown(0, 0, {
// middle mouse button
button: 1,
})
editor.pointerMove(100, 100)
expect(editor.inputs.isPanning).toBe(true)
editor.keyDown(' ')
editor.pointerUp(100, 100, {
button: 1,
})
expect(editor.inputs.isPanning).toBe(true)

editor.keyUp(' ')
expect(editor.inputs.isPanning).toBe(false)
})
})

0 comments on commit 1452978

Please sign in to comment.