mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-16 05:50:03 +02:00
fix: Dragging issues
This commit is contained in:
@@ -46,6 +46,7 @@ import type {
|
|||||||
import {
|
import {
|
||||||
calculateFixedPointForNonElbowArrowBinding,
|
calculateFixedPointForNonElbowArrowBinding,
|
||||||
getBindingStrategyForDraggingBindingElementEndpoints,
|
getBindingStrategyForDraggingBindingElementEndpoints,
|
||||||
|
getFixedBindingDistance,
|
||||||
isBindingEnabled,
|
isBindingEnabled,
|
||||||
maybeSuggestBindingsForBindingElementAtCoords,
|
maybeSuggestBindingsForBindingElementAtCoords,
|
||||||
unbindBindingElement,
|
unbindBindingElement,
|
||||||
@@ -2159,8 +2160,18 @@ const pointDraggingUpdates = (
|
|||||||
),
|
),
|
||||||
offsetEndLocalPoint,
|
offsetEndLocalPoint,
|
||||||
],
|
],
|
||||||
startBinding: updates.startBinding ?? element.startBinding,
|
startBinding:
|
||||||
endBinding: updates.endBinding ?? element.endBinding,
|
updates.startBinding === undefined
|
||||||
|
? element.startBinding
|
||||||
|
: updates.startBinding === null
|
||||||
|
? null
|
||||||
|
: updates.startBinding,
|
||||||
|
endBinding:
|
||||||
|
updates.endBinding === undefined
|
||||||
|
? element.endBinding
|
||||||
|
: updates.endBinding === null
|
||||||
|
? null
|
||||||
|
: updates.endBinding,
|
||||||
};
|
};
|
||||||
|
|
||||||
// We need to use a custom intersector to ensure that if there is a big "jump"
|
// We need to use a custom intersector to ensure that if there is a big "jump"
|
||||||
@@ -2224,7 +2235,11 @@ const pointDraggingUpdates = (
|
|||||||
const indices = Array.from(indicesSet);
|
const indices = Array.from(indicesSet);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
updates: start.mode || end.mode ? updates : undefined,
|
updates:
|
||||||
|
Object.hasOwn(updates, "startBinding") ||
|
||||||
|
Object.hasOwn(updates, "endBinding")
|
||||||
|
? updates
|
||||||
|
: undefined,
|
||||||
positions: new Map(
|
positions: new Map(
|
||||||
indices.map((idx) => {
|
indices.map((idx) => {
|
||||||
return [
|
return [
|
||||||
@@ -2259,10 +2274,13 @@ const shouldAllowDraggingPoint = (
|
|||||||
let allowDrag = true;
|
let allowDrag = true;
|
||||||
|
|
||||||
if (selectedPointsIndices.includes(0) && element.startBinding) {
|
if (selectedPointsIndices.includes(0) && element.startBinding) {
|
||||||
const boundElement = elementsMap.get(element.startBinding.elementId)!;
|
const boundElement = elementsMap.get(
|
||||||
|
element.startBinding.elementId,
|
||||||
|
)! as ExcalidrawBindableElement;
|
||||||
const dist = distanceToElement(boundElement, elementsMap, scenePointer);
|
const dist = distanceToElement(boundElement, elementsMap, scenePointer);
|
||||||
const inside = isPointInElement(scenePointer, boundElement, elementsMap);
|
const inside = isPointInElement(scenePointer, boundElement, elementsMap);
|
||||||
allowDrag = allowDrag && (dist > DRAGGING_THRESHOLD || inside);
|
allowDrag =
|
||||||
|
allowDrag && (dist > getFixedBindingDistance(boundElement) || inside);
|
||||||
if (allowDrag) {
|
if (allowDrag) {
|
||||||
unbindBindingElement(element, "start", app.scene);
|
unbindBindingElement(element, "start", app.scene);
|
||||||
}
|
}
|
||||||
@@ -2271,10 +2289,13 @@ const shouldAllowDraggingPoint = (
|
|||||||
selectedPointsIndices.includes(element.points.length - 1) &&
|
selectedPointsIndices.includes(element.points.length - 1) &&
|
||||||
element.endBinding
|
element.endBinding
|
||||||
) {
|
) {
|
||||||
const boundElement = elementsMap.get(element.endBinding.elementId)!;
|
const boundElement = elementsMap.get(
|
||||||
|
element.endBinding.elementId,
|
||||||
|
)! as ExcalidrawBindableElement;
|
||||||
const dist = distanceToElement(boundElement, elementsMap, scenePointer);
|
const dist = distanceToElement(boundElement, elementsMap, scenePointer);
|
||||||
const inside = isPointInElement(scenePointer, boundElement, elementsMap);
|
const inside = isPointInElement(scenePointer, boundElement, elementsMap);
|
||||||
allowDrag = allowDrag && (dist > DRAGGING_THRESHOLD || inside);
|
allowDrag =
|
||||||
|
allowDrag && (dist > getFixedBindingDistance(boundElement) || inside);
|
||||||
if (allowDrag) {
|
if (allowDrag) {
|
||||||
unbindBindingElement(element, "end", app.scene);
|
unbindBindingElement(element, "end", app.scene);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user