The personal finance app for everyone (by everyone)
Ruby
Use nearest-edge distance for symmetrical drag reorder of tall sections
juan53c5f5759d0d
diff --git a/app/javascript/controllers/dashboard_sortable_controller.js b/app/javascript/controllers/dashboard_sortable_controller.jsindex c0a0cbccad..c1ab017807 100644--- a/app/javascript/controllers/dashboard_sortable_controller.js+++ b/app/javascript/controllers/dashboard_sortable_controller.js@@ -295,10 +295,19 @@ export default class extends Controller {draggableElements.forEach((child) => {const rect = child.getBoundingClientRect();const centerX = rect.left + rect.width / 2;- const centerY = rect.top + rect.height / 2;+ // Use distance to nearest edge instead of center so tall sections+ // don't require more finger travel than short onesconst dx = pointerX - centerX;- const dy = pointerY - centerY;+ let dy;+ if (pointerY < rect.top) {+ dy = rect.top - pointerY;+ } else if (pointerY > rect.bottom) {+ dy = pointerY - rect.bottom;+ } else {+ dy = 0; // pointer is within this section's vertical bounds+ }+const distance = Math.sqrt(dx * dx + dy * dy);if (distance < minDistance) {