Skip to content

Commit

Permalink
feat: improve elbow arrow keyboard move (excalidraw#8392)
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian authored and clarencechaan committed Oct 3, 2024
1 parent 279280a commit 3f72ae2
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions packages/excalidraw/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4062,7 +4062,7 @@ class App extends React.Component<AppProps, AppState> {
}

if (isArrowKey(event.key)) {
const selectedElements = this.scene.getSelectedElements({
let selectedElements = this.scene.getSelectedElements({
selectedElementIds: this.state.selectedElementIds,
includeBoundTextElement: true,
includeElementsInFrames: true,
Expand All @@ -4072,17 +4072,37 @@ class App extends React.Component<AppProps, AppState> {
| ExcalidrawArrowElement
| undefined;

const step = elbowArrow
? elbowArrow.startBinding || elbowArrow.endBinding
? 0
: ELEMENT_TRANSLATE_AMOUNT
: (this.getEffectiveGridSize() &&
(event.shiftKey
? ELEMENT_TRANSLATE_AMOUNT
: this.getEffectiveGridSize())) ||
const arrowIdsToRemove = new Set<string>();

selectedElements
.filter(isElbowArrow)
.filter((arrow) => {
const startElementNotInSelection =
arrow.startBinding &&
!selectedElements.some(
(el) => el.id === arrow.startBinding?.elementId,
);
const endElementNotInSelection =
arrow.endBinding &&
!selectedElements.some(
(el) => el.id === arrow.endBinding?.elementId,
);
return startElementNotInSelection || endElementNotInSelection;
})
.forEach((arrow) => arrowIdsToRemove.add(arrow.id));

selectedElements = selectedElements.filter(
(el) => !arrowIdsToRemove.has(el.id),
);

const step =
(this.getEffectiveGridSize() &&
(event.shiftKey
? ELEMENT_SHIFT_TRANSLATE_AMOUNT
: ELEMENT_TRANSLATE_AMOUNT);
? ELEMENT_TRANSLATE_AMOUNT
: this.getEffectiveGridSize())) ||
(event.shiftKey
? ELEMENT_SHIFT_TRANSLATE_AMOUNT
: ELEMENT_TRANSLATE_AMOUNT);

let offsetX = 0;
let offsetY = 0;
Expand Down

0 comments on commit 3f72ae2

Please sign in to comment.