feat: Center binding on SHIFT key

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs
2025-09-29 10:55:02 +02:00
parent 0232917443
commit 1744c7aa56
2 changed files with 12 additions and 3 deletions

View File

@@ -241,6 +241,7 @@ const bindingStrategyForNewSimpleArrowEndpointDragging = (
endIdx: number,
appState: AppState,
globalBindMode?: AppState["bindMode"],
shiftKey?: boolean,
): {
start: BindingStrategy;
end: BindingStrategy;
@@ -334,12 +335,11 @@ const bindingStrategyForNewSimpleArrowEndpointDragging = (
const otherIsInsideBinding =
!!appState.selectedLinearElement?.initialState.arrowStartIsInside;
const other: BindingStrategy = {
mode: otherIsInsideBinding ? "inside" : "orbit",
element: otherElement,
focusPoint: otherIsInsideBinding
? origin ?? pointFrom<GlobalPoint>(arrow.x, arrow.y)
focusPoint: shiftKey
? elementCenterPoint(otherElement, elementsMap)
: origin ?? pointFrom<GlobalPoint>(arrow.x, arrow.y),
};
@@ -396,6 +396,7 @@ const bindingStrategyForSimpleArrowEndpointDragging = (
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
globalBindMode: AppState["bindMode"],
arrow: NonDeleted<ExcalidrawArrowElement>,
shiftKey?: boolean,
): { current: BindingStrategy; other: BindingStrategy } => {
let current: BindingStrategy = { mode: undefined };
let other: BindingStrategy = { mode: undefined };
@@ -515,6 +516,7 @@ export const getBindingStrategyForDraggingBindingElementEndpoints = (
appState: AppState,
opts?: {
newArrow?: boolean;
shiftKey?: boolean;
},
): { start: BindingStrategy; end: BindingStrategy } => {
const globalBindMode = appState.bindMode || "orbit";
@@ -574,6 +576,7 @@ export const getBindingStrategyForDraggingBindingElementEndpoints = (
endIdx,
appState,
globalBindMode,
opts?.shiftKey,
);
return { start, end };
@@ -597,6 +600,7 @@ export const getBindingStrategyForDraggingBindingElementEndpoints = (
elements,
globalBindMode,
arrow,
opts?.shiftKey,
);
return { start: current, end: other };
@@ -619,6 +623,7 @@ export const getBindingStrategyForDraggingBindingElementEndpoints = (
elements,
globalBindMode,
arrow,
opts?.shiftKey,
);
return { start: other, end: current };

View File

@@ -354,6 +354,7 @@ export class LinearElementEditor {
element,
elements,
app,
event.shiftKey,
);
LinearElementEditor.movePoints(element, app.scene, positions, {
@@ -517,6 +518,7 @@ export class LinearElementEditor {
element,
elements,
app,
event.shiftKey,
);
LinearElementEditor.movePoints(element, app.scene, positions, {
@@ -2054,6 +2056,7 @@ const pointDraggingUpdates = (
element: NonDeleted<ExcalidrawLinearElement>,
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
app: AppClassProperties,
shiftKey: boolean,
): {
positions: PointsPositionUpdates;
updates?: PointMoveOtherUpdates;
@@ -2099,6 +2102,7 @@ const pointDraggingUpdates = (
app.state,
{
newArrow: !!app.state.newElement,
shiftKey,
},
);