Fix binding
This commit is contained in:
parent
6deb4fdbe6
commit
cf9bfb5ebd
@ -410,41 +410,36 @@ export const maybeSuggestBindingsForLinearElementAtCoords = (
|
|||||||
// During line creation the start binding hasn't been written yet
|
// During line creation the start binding hasn't been written yet
|
||||||
// into `linearElement`
|
// into `linearElement`
|
||||||
oppositeBindingBoundElement?: ExcalidrawBindableElement | null,
|
oppositeBindingBoundElement?: ExcalidrawBindableElement | null,
|
||||||
): ExcalidrawBindableElement[] => {
|
): ExcalidrawBindableElement[] =>
|
||||||
if (!pointerCoords.length) {
|
Array.from(
|
||||||
return [];
|
pointerCoords.reduce(
|
||||||
}
|
(acc: Set<NonDeleted<ExcalidrawBindableElement>>, coords) => {
|
||||||
|
const hoveredBindableElement = getHoveredElementForBinding(
|
||||||
|
coords,
|
||||||
|
scene.getNonDeletedElements(),
|
||||||
|
scene.getNonDeletedElementsMap(),
|
||||||
|
zoom,
|
||||||
|
isElbowArrow(linearElement),
|
||||||
|
isElbowArrow(linearElement),
|
||||||
|
);
|
||||||
|
|
||||||
const suggestedBindings = pointerCoords.reduce(
|
if (
|
||||||
(acc: Set<NonDeleted<ExcalidrawBindableElement>>, coords) => {
|
hoveredBindableElement != null &&
|
||||||
const hoveredBindableElement = getHoveredElementForBinding(
|
!isLinearElementSimpleAndAlreadyBound(
|
||||||
coords,
|
linearElement,
|
||||||
scene.getNonDeletedElements(),
|
oppositeBindingBoundElement?.id,
|
||||||
scene.getNonDeletedElementsMap(),
|
hoveredBindableElement,
|
||||||
zoom,
|
)
|
||||||
isElbowArrow(linearElement),
|
) {
|
||||||
isElbowArrow(linearElement),
|
acc.add(hoveredBindableElement);
|
||||||
);
|
}
|
||||||
|
|
||||||
if (
|
return acc;
|
||||||
hoveredBindableElement != null &&
|
},
|
||||||
!isLinearElementSimpleAndAlreadyBound(
|
new Set() as Set<NonDeleted<ExcalidrawBindableElement>>,
|
||||||
linearElement,
|
),
|
||||||
oppositeBindingBoundElement?.id,
|
|
||||||
hoveredBindableElement,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
acc.add(hoveredBindableElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
new Set() as Set<NonDeleted<ExcalidrawBindableElement>>,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return Array.from(suggestedBindings);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const maybeBindLinearElement = (
|
export const maybeBindLinearElement = (
|
||||||
linearElement: NonDeleted<ExcalidrawLinearElement>,
|
linearElement: NonDeleted<ExcalidrawLinearElement>,
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
|
@ -18,6 +18,7 @@ import {
|
|||||||
getGridPoint,
|
getGridPoint,
|
||||||
invariant,
|
invariant,
|
||||||
tupleToCoors,
|
tupleToCoors,
|
||||||
|
viewportCoordsToSceneCoords,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import type { Store } from "@excalidraw/element";
|
import type { Store } from "@excalidraw/element";
|
||||||
@ -458,6 +459,7 @@ export class LinearElementEditor {
|
|||||||
): LinearElementEditor {
|
): LinearElementEditor {
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
const elements = scene.getNonDeletedElements();
|
const elements = scene.getNonDeletedElements();
|
||||||
|
const pointerCoords = viewportCoordsToSceneCoords(event, appState);
|
||||||
|
|
||||||
const { elementId, selectedPointsIndices, isDragging, pointerDownState } =
|
const { elementId, selectedPointsIndices, isDragging, pointerDownState } =
|
||||||
editingLinearElement;
|
editingLinearElement;
|
||||||
@ -501,13 +503,7 @@ export class LinearElementEditor {
|
|||||||
|
|
||||||
const bindingElement = isBindingEnabled(appState)
|
const bindingElement = isBindingEnabled(appState)
|
||||||
? getHoveredElementForBinding(
|
? getHoveredElementForBinding(
|
||||||
tupleToCoors(
|
pointerCoords,
|
||||||
LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
|
||||||
element,
|
|
||||||
selectedPoint!,
|
|
||||||
elementsMap,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
elements,
|
elements,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
appState.zoom,
|
appState.zoom,
|
||||||
|
@ -9755,7 +9755,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
pointerDownState.drag.hasOccurred ||
|
(pointerDownState.drag.hasOccurred &&
|
||||||
|
!this.state.selectedLinearElement) ||
|
||||||
isResizing ||
|
isResizing ||
|
||||||
isRotating ||
|
isRotating ||
|
||||||
isCropping
|
isCropping
|
||||||
|
Loading…
x
Reference in New Issue
Block a user