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

View File

@ -371,33 +371,40 @@ export class LinearElementEditor {
// suggest bindings for first and last point if selected // suggest bindings for first and last point if selected
let suggestedBindings: ExcalidrawBindableElement[] = []; let suggestedBindings: ExcalidrawBindableElement[] = [];
if (isBindingElement(element, false)) { 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 coords: { x: number; y: number }[] = [];
const firstSelectedIndex = selectedPointsIndices[0]; if (!firstSelectedIndex !== !lastSelectedIndex) {
if (firstSelectedIndex === 0) { coords.push({ x: scenePointerX, y: scenePointerY });
coords.push( } else {
tupleToCoors( if (firstSelectedIndex) {
LinearElementEditor.getPointGlobalCoordinates( coords.push(
element, tupleToCoors(
element.points[0], LinearElementEditor.getPointGlobalCoordinates(
elementsMap, element,
element.points[0],
elementsMap,
),
), ),
), );
); }
}
const lastSelectedIndex = if (lastSelectedIndex) {
selectedPointsIndices[selectedPointsIndices.length - 1]; coords.push(
if (lastSelectedIndex === element.points.length - 1) { tupleToCoors(
coords.push( LinearElementEditor.getPointGlobalCoordinates(
tupleToCoors( element,
LinearElementEditor.getPointGlobalCoordinates( element.points[
element, selectedPointsIndices[selectedPointsIndices.length - 1]
element.points[lastSelectedIndex], ],
elementsMap, elementsMap,
),
), ),
), );
); }
} }
if (coords.length) { if (coords.length) {