Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

Refactor note collision resolution in ComponentSort.ts to optimize overlap detection and shifting logic. Collect overlapping components into an array and shift only those, improving performance and readability.

Muhammad Hamza Khan955c722cd063
diff --git a/packages/app/src/builder-ui/workspace/ComponentSort.ts b/packages/app/src/builder-ui/workspace/ComponentSort.ts
index 528c01a8..e487a84b 100644
--- a/packages/app/src/builder-ui/workspace/ComponentSort.ts
+++ b/packages/app/src/builder-ui/workspace/ComponentSort.ts
@@ -192,33 +192,28 @@ async function resolveNoteCollisions(
for (const noteGroup of noteGroups) {
const noteBounds = getElementBounds(noteGroup.noteElement);
const noteRightEdge = noteBounds.left + noteBounds.width;
- let minOverlapX = Infinity;
- let hasOverlap = false;
- // Find minimum X of overlapping components
+ // Collect only components that actually overlap with this Note
+ const overlappingComponents: Array<{ element: HTMLElement; bounds: Bounds }> = [];
+
for (const compEl of allComponents) {
if (originallyContainedIds.has(compEl.id)) continue;
const compBounds = getElementBounds(compEl);
if (rectanglesOverlap(noteBounds, compBounds)) {
- hasOverlap = true;
- minOverlapX = Math.min(minOverlapX, compBounds.left);
+ overlappingComponents.push({ element: compEl, bounds: compBounds });
}
}
- if (!hasOverlap) continue;
-
- const shiftAmount = noteRightEdge + padding - minOverlapX;
- if (shiftAmount <= 0) continue;
-
- // Shift all components at or beyond the overlap point
- for (const compEl of allComponents) {
- if (originallyContainedIds.has(compEl.id)) continue;
+ // Skip if no actual overlaps with this Note
+ if (overlappingComponents.length === 0) continue;
- const compLeft = parseFloat(compEl.style.left) || 0;
- if (compLeft >= minOverlapX) {
- compEl.style.transition = '0.2s ease-in-out';
- compEl.style.left = `${~~(compLeft + shiftAmount)}px`;
+ // Shift only the components that actually overlap with the Note
+ for (const { element, bounds } of overlappingComponents) {
+ const shiftAmount = noteRightEdge + padding - bounds.left;
+ if (shiftAmount > 0) {
+ element.style.transition = '0.2s ease-in-out';
+ element.style.left = `${~~(bounds.left + shiftAmount)}px`;
}
}
}