Modern Apps git

← Modern-Apps.git

launcher: wide drops shove both occupants along instead of giving up

Commit
d2bc814a5bc72a909f17b4048f87a34ac72d7102
Author
Vayun Mathur <[email protected]>
When
2026-12-01 19:52 UTC (4 days ago)
Parents
0706fb3
GridReorder.pushAlong cleared every occupant of the wanted region
to the region's leading edge and then refused to move any of them
again. A region more than one cell wide along the push direction
therefore sent two occupants to the same cell and aborted the
whole cascade, even when free cells lay beyond them: a 2-wide
widget dropped rightwards over two icons in a row, or a 2-tall
item dropped downwards over two stacked icons, fell back to
GridPreview's push-aside scattering instead of shuffling along
the drag, and a widget resize through WidgetResize.resizeWithPush
(which has no fallback) was refused outright.

The cascade now allows a re-push when another occupant lands on
the cell an item was first pushed to, provided it moves strictly
further along the push direction; queue entries superseded by a
later push of their owner are skipped so a pair cannot ping-pong.
Progress is monotonic and bounded by the grid, so the cascade
still terminates and still abandons whole when it hits a wall.

Two regression tests cover the wide (push right) and tall (push
down) forms, asserting both occupants move in their original
order into distinct cells. They fail on the old code (both
return null) and pass with the fix. Verified with
:launcher:testDevUnitTest, targeted first (GridReorder,
GridPreview and WidgetResize suites) and then the full suite,
which is green. The module's pre-existing
ktlint backlog (including the touched files' existing lines) is
unchanged by this change.

Diff

launcher/src/main/java/com/vayunmathur/launcher/domain/GridReorder.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/domain/GridReorder.kt b/launcher/src/main/java/com/vayunmathur/launcher/domain/GridReorder.ktindex 3ef4385681..37450a07d1 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/domain/GridReorder.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/domain/GridReorder.kt@@ -44,10 +44,14 @@ object GridReorder {      * Where each item has to go for [wanted] to be free, pushing along [direction], or null when      * some item in the chain would end up off the grid.      *-     * Breadth-first over the chain rather than recursive descent, so the cascade is bounded by the-     * number of items on the page: each one may move at most once, and a second push of the same-     * item aborts the whole plan. Without that, two items shoved into each other's paths would-     * loop.+     * Breadth-first over the chain rather than recursive descent. An item may be pushed+     * again when another occupant lands on the cell it was first pushed to — a region+     * wider than one cell sends every occupant to the same leading edge, so the ones+     * behind have to shove the ones in front one cell further to keep their order and+     * end in distinct cells. A re-push only ever moves an item strictly further along+     * [direction] and stays on the grid, so the cascade is bounded by the grid's extent+     * in that direction and cannot loop; a re-push that makes no progress aborts the+     * whole plan.      */     fun pushAlong(         spec: GridSpec,@@ -65,12 +69,17 @@ object GridReorder {          while (pending.isNotEmpty()) {             val (owner, region) = pending.removeFirst()+            // Superseded entry: the owner has since been pushed further, so this older+            // region is no longer where it sits. Acting on it would push the items now+            // there back into the owner's path and ping-pong the pair along the grid.+            if (owner != null && layout[owner] != region) continue             val blocking = layout                 .filter { it.key != owner && it.value.overlaps(region) }                 .map { it.key to it.value }             for ((id, rect) in blocking) {-                if (id in moved) return null-                val to = shiftedClear(rect, region, direction)+                val current = layout[id] ?: rect+                val to = shiftedClear(current, region, direction)+                if (id in moved && !isFurther(current, to, direction)) return null                 if (!fits(spec, to)) return null                 layout[id] = to                 moved[id] = to@@ -80,6 +89,15 @@ object GridReorder {         return moved     } +    /** Whether [to] lies strictly beyond [from] along [direction]. */+    private fun isFurther(from: CellRect, to: CellRect, direction: PushDirection): Boolean =+        when (direction) {+            PushDirection.Right -> to.cellX > from.cellX+            PushDirection.Left -> to.cellX < from.cellX+            PushDirection.Down -> to.cellY > from.cellY+            PushDirection.Up -> to.cellY < from.cellY+        }+     /** [rect] moved the fewest whole cells along [direction] that takes it clear of [region]. */     private fun shiftedClear(rect: CellRect, region: CellRect, direction: PushDirection): CellRect =         when (direction) {
launcher/src/test/java/com/vayunmathur/launcher/domain/LauncherDomainTest.kt
diff --git a/launcher/src/test/java/com/vayunmathur/launcher/domain/LauncherDomainTest.kt b/launcher/src/test/java/com/vayunmathur/launcher/domain/LauncherDomainTest.ktindex 0d4b2f615a..690b07b5ef 100644--- a/launcher/src/test/java/com/vayunmathur/launcher/domain/LauncherDomainTest.kt+++ b/launcher/src/test/java/com/vayunmathur/launcher/domain/LauncherDomainTest.kt@@ -687,6 +687,24 @@ class GridReorderTest {     fun `a region off the grid cannot be made room for`() {         assertNull(GridReorder.pushAlong(spec, emptyMap(), CellRect(3, 0, 2, 1), PushDirection.Right))     }++    @Test+    fun `a wide region shoves both occupants along in their original order`() {+        // A 2-wide item dropped over two 1-wide icons in the same row, pushing right.+        // Both occupants initially clear to the region's right edge (x=2), so the+        // left-hand one must then shove the right-hand one one cell further, keeping+        // their order; the grid has room (x=3 is free), so the push must not give up.+        val others = mapOf(1L to CellRect(0, 0), 2L to CellRect(1, 0))+        val moves = GridReorder.pushAlong(spec, others, CellRect(0, 0, 2, 1), PushDirection.Right)+        assertEquals(mapOf(1L to CellRect(2, 0), 2L to CellRect(3, 0)), moves)+    }++    @Test+    fun `a tall region shoves both occupants down in their original order`() {+        val others = mapOf(1L to CellRect(0, 0), 2L to CellRect(0, 1))+        val moves = GridReorder.pushAlong(spec, others, CellRect(0, 0, 1, 2), PushDirection.Down)+        assertEquals(mapOf(1L to CellRect(0, 2), 2L to CellRect(0, 3)), moves)+    } }  class ReorderDwellTest {