diff --git a/e2e/forks.spec.ts b/e2e/forks.spec.ts index 34c7408..f852cc4 100644 --- a/e2e/forks.spec.ts +++ b/e2e/forks.spec.ts @@ -510,6 +510,9 @@ test("a pane is dragged by its grip, or its tab, up or down its column; the orde await page.reload(); await page.waitForSelector(".strip .pane"); expect((await columns(page))[1]).toEqual([kids[4], ...kids.slice(0, 4)]); + // Downward, reaching the top of a pane below is enough: the dragged pane lands after it. + await drag(kids[4], kids[1]); + expect((await columns(page))[1]).toEqual([kids[0], kids[1], kids[4], kids[2], kids[3]]); // And by its tab, in a crowded column. await page.setViewportSize({ width: 1920, height: 1080 }); await expect.poll(() => page.locator(".strip > .col").nth(1).getAttribute("class")).toContain("crowded"); diff --git a/src/ui/Panes.tsx b/src/ui/Panes.tsx index e83a0e2..bd7ea7f 100644 --- a/src/ui/Panes.tsx +++ b/src/ui/Panes.tsx @@ -572,13 +572,21 @@ export function Panes() { drag.line.className = "drop-line"; wrap.appendChild(drag.line); } - const others = [...drag.col.querySelectorAll(":scope > .pane")].filter((p) => Number(p.dataset.tid) !== drag!.tid); + const panes = [...drag.col.querySelectorAll(":scope > .pane")]; + const mine = panes.findIndex((p) => Number(p.dataset.tid) === drag!.tid); + const others = panes.filter((_, k) => k !== mine); const c = drag.col.getBoundingClientRect(); const tops = others.map((p) => Math.max(c.top, Math.min(c.bottom, p.getBoundingClientRect().top))); const ends = others.map((p, i) => Math.min(tops[i + 1] ?? c.bottom, Math.max(c.top, Math.min(c.bottom, p.getBoundingClientRect().bottom)))); - const i = others.findIndex((_, k) => e.clientY < (tops[k] + ends[k]) / 2); + // The pane under the pointer gives way: one that was below the dragged pane lets it in after + // itself, one that was above lets it in before. So reaching any part of a pane is enough, in + // either direction. + let k = -1; + while (k + 1 < others.length && tops[k + 1] <= e.clientY) k++; + const at = k < 0 ? 0 : k >= mine || e.clientY >= ends[k] ? k + 1 : k; + const i = at < others.length ? at : -1; drag.before = i < 0 ? null : Number(others[i].dataset.tid); - const y = i < 0 ? (ends[ends.length - 1] ?? c.top) : tops[i]; + const y = at === 0 ? (tops[0] ?? c.top) : ends[at - 1]; const box = wrap.getBoundingClientRect(); Object.assign(drag.line!.style, { left: `${c.left - box.left}px`, width: `${c.width}px`, top: `${y - box.top - 1}px` }); };