Skip to content

Commit

Permalink
improved check for attached edges
Browse files Browse the repository at this point in the history
this is a followup for #442
  • Loading branch information
jbicker committed Mar 7, 2024
1 parent 31b428b commit 65596fa
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions packages/sprotty/src/features/move/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,25 +211,22 @@ export class MoveCommand extends MergeableCommand implements IStoppableCommand {
const source = edge.source;
const target = edge.target;
const checkMovedElementsAndChildren = (sourceOrTarget: SConnectableElementImpl): boolean => {
return Array.from(this.resolvedMoves.values()).some(res => {
const recursiveCheck = (el: SModelElementImpl): boolean => {
if (isParent(el)) {
return el.children.some(child => {
if (child instanceof SModelElementImpl) {
if (child === sourceOrTarget)
return true;
return recursiveCheck(child);
}
return false;
});
}
return false;
};
return recursiveCheck(res.element);
}) || !!(this.resolvedMoves.get(sourceOrTarget.id));
const recursiveCheck = (el: SChildElementImpl): boolean => {
const parent = el.parent;
if (Array.from(this.resolvedMoves.values()).map(rm => rm.element.id).includes(parent.id)) {
return true;
}
if (parent instanceof SChildElementImpl) {
return recursiveCheck(parent);
}
return false;
};
const isChildOfMovedElement = recursiveCheck(sourceOrTarget);

return isChildOfMovedElement || Boolean(this.resolvedMoves.get(sourceOrTarget.id));
};

return !!(
return Boolean(
source &&
target &&
checkMovedElementsAndChildren(source) &&
Expand Down

0 comments on commit 65596fa

Please sign in to comment.