mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat:prevent unwanted movements of elements on mouse click
This commit is contained in:
parent
96ed8a4331
commit
ce10654235
1 changed files with 29 additions and 0 deletions
|
@ -531,6 +531,7 @@ let isDraggingScrollBar: boolean = false;
|
|||
let currentScrollBars: ScrollBars = { horizontal: null, vertical: null };
|
||||
let touchTimeout = 0;
|
||||
let invalidateContextMenu = false;
|
||||
let elementStartedMoving = false;
|
||||
|
||||
/**
|
||||
* Map of youtube embed video states
|
||||
|
@ -7900,6 +7901,31 @@ class App extends React.Component<AppProps, AppState> {
|
|||
!this.state.editingTextElement &&
|
||||
this.state.activeEmbeddable?.state !== "active"
|
||||
) {
|
||||
|
||||
if(!this.state.editingLinearElement && !this.state.editingFrame && !this.state.resizingElement){
|
||||
|
||||
// this determines the threshold for dragging the element initially
|
||||
const MOVEMENT_BUFFER = 4;
|
||||
|
||||
// this calculates the buffer for the movement based on the zoom level
|
||||
const ZOOM_RELETIVE_MOVEMENT_BUFFER = MOVEMENT_BUFFER / this.state.zoom.value;
|
||||
|
||||
if(typeof(ZOOM_RELETIVE_MOVEMENT_BUFFER) === 'number'){
|
||||
|
||||
if (
|
||||
pointDistance(
|
||||
pointFrom(pointerCoords.x, pointerCoords.y),
|
||||
pointFrom(pointerDownState.origin.x, pointerDownState.origin.y),
|
||||
) < ZOOM_RELETIVE_MOVEMENT_BUFFER && !elementStartedMoving
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// sets the elementStartedMoving to true so that the buffer is only used once
|
||||
elementStartedMoving = true;
|
||||
}
|
||||
|
||||
const dragOffset = {
|
||||
x: pointerCoords.x - pointerDownState.origin.x,
|
||||
y: pointerCoords.y - pointerDownState.origin.y,
|
||||
|
@ -8408,6 +8434,9 @@ class App extends React.Component<AppProps, AppState> {
|
|||
isCropping,
|
||||
} = this.state;
|
||||
|
||||
// sets the elementStartedMoving to false so that the buffer can be used again
|
||||
elementStartedMoving = false;
|
||||
|
||||
this.setState((prevState) => ({
|
||||
isResizing: false,
|
||||
isRotating: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue