Skip to content

Commit fc388b6

Browse files
authored
Merge pull request #1434 from paulkaplan/stage-drag-threshold
Apply a drag threshold to make clicking sprites easier
2 parents 75b4be8 + a163228 commit fc388b6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/containers/stage.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from '../reducers/color-picker';
1616

1717
const colorPickerRadius = 20;
18+
const dragThreshold = 3; // Same as the block drag threshold
1819

1920
class Stage extends React.Component {
2021
constructor (props) {
@@ -149,9 +150,13 @@ class Stage extends React.Component {
149150
this.pickX = mousePosition[0];
150151
this.pickY = mousePosition[1];
151152

152-
if (this.state.mouseDownTimeoutId !== null) {
153-
this.cancelMouseDownTimeout();
154-
if (this.state.mouseDown && !this.state.isDragging) {
153+
if (this.state.mouseDown && !this.state.isDragging) {
154+
const distanceFromMouseDown = Math.sqrt(
155+
Math.pow(mousePosition[0] - this.state.mouseDownPosition[0], 2) +
156+
Math.pow(mousePosition[1] - this.state.mouseDownPosition[1], 2)
157+
);
158+
if (distanceFromMouseDown > dragThreshold) {
159+
this.cancelMouseDownTimeout();
155160
this.onStartDrag(...this.state.mouseDownPosition);
156161
}
157162
}

0 commit comments

Comments
 (0)