Fix the highlight part of the issue

This commit is contained in:
Mark Tolmacs 2025-05-16 17:01:31 +02:00
parent 9af3177dbd
commit 6deb4fdbe6
No known key found for this signature in database
2 changed files with 36 additions and 27 deletions

View File

@ -416,7 +416,7 @@ export const maybeSuggestBindingsForLinearElementAtCoords = (
}
const suggestedBindings = pointerCoords.reduce(
(acc: NonDeleted<ExcalidrawBindableElement>[], coords) => {
(acc: Set<NonDeleted<ExcalidrawBindableElement>>, coords) => {
const hoveredBindableElement = getHoveredElementForBinding(
coords,
scene.getNonDeletedElements(),
@ -425,6 +425,7 @@ export const maybeSuggestBindingsForLinearElementAtCoords = (
isElbowArrow(linearElement),
isElbowArrow(linearElement),
);
if (
hoveredBindableElement != null &&
!isLinearElementSimpleAndAlreadyBound(
@ -433,14 +434,15 @@ export const maybeSuggestBindingsForLinearElementAtCoords = (
hoveredBindableElement,
)
) {
acc.push(hoveredBindableElement);
acc.add(hoveredBindableElement);
}
return acc;
},
[],
new Set() as Set<NonDeleted<ExcalidrawBindableElement>>,
);
return suggestedBindings;
return Array.from(suggestedBindings);
};
export const maybeBindLinearElement = (
@ -580,7 +582,7 @@ export const isLinearElementSimpleAndAlreadyBound = (
const isLinearElementSimple = (
linearElement: NonDeleted<ExcalidrawLinearElement>,
): boolean => linearElement.points.length < 3;
): boolean => linearElement.points.length < 3 && !isElbowArrow(linearElement);
const unbindLinearElement = (
linearElement: NonDeleted<ExcalidrawLinearElement>,

View File

@ -371,10 +371,16 @@ export class LinearElementEditor {
// suggest bindings for first and last point if selected
let suggestedBindings: ExcalidrawBindableElement[] = [];
if (isBindingElement(element, false)) {
const firstSelectedIndex = selectedPointsIndices[0] === 0;
const lastSelectedIndex =
selectedPointsIndices[selectedPointsIndices.length - 1] ===
element.points.length - 1;
const coords: { x: number; y: number }[] = [];
const firstSelectedIndex = selectedPointsIndices[0];
if (firstSelectedIndex === 0) {
if (!firstSelectedIndex !== !lastSelectedIndex) {
coords.push({ x: scenePointerX, y: scenePointerY });
} else {
if (firstSelectedIndex) {
coords.push(
tupleToCoors(
LinearElementEditor.getPointGlobalCoordinates(
@ -386,19 +392,20 @@ export class LinearElementEditor {
);
}
const lastSelectedIndex =
selectedPointsIndices[selectedPointsIndices.length - 1];
if (lastSelectedIndex === element.points.length - 1) {
if (lastSelectedIndex) {
coords.push(
tupleToCoors(
LinearElementEditor.getPointGlobalCoordinates(
element,
element.points[lastSelectedIndex],
element.points[
selectedPointsIndices[selectedPointsIndices.length - 1]
],
elementsMap,
),
),
);
}
}
if (coords.length) {
suggestedBindings = maybeSuggestBindingsForLinearElementAtCoords(