diff --git a/packages/desktop/assets/tabs.html b/packages/desktop/assets/tabs.html index 7fd20099..e5298f88 100644 --- a/packages/desktop/assets/tabs.html +++ b/packages/desktop/assets/tabs.html @@ -449,9 +449,14 @@ dx = Math.max(minDx, Math.min(maxDx, dx)); drag.root.style.transform = 'translateX(' + dx + 'px)'; var centre = r0.left + r0.width / 2 + dx; + // A tab after the dragged one is passed once the centres meet, not only once they cross: + // the clamp stops a tab dragged all the way right with its centre ON the last tab's + // centre, and a strict comparison there left it one place short of the end. var to = 0; for (var i = 0; i < rects.length; i++) { - if (i !== drag.from && centre > rects[i].left + rects[i].width / 2) to++; + if (i === drag.from) continue; + var c = rects[i].left + rects[i].width / 2; + if (i > drag.from ? centre >= c : centre > c) to++; } drag.to = to; drag.roots.forEach(function (r, i) { diff --git a/test/desktop-tabs-pages.browser.test.ts b/test/desktop-tabs-pages.browser.test.ts index 6fa098a3..fa806490 100644 --- a/test/desktop-tabs-pages.browser.test.ts +++ b/test/desktop-tabs-pages.browser.test.ts @@ -472,6 +472,14 @@ async function stripWalk(browser: Browser) { same(await order(), [14, 12, 13, 11]) && (await page.textContent(sel(12, '.name'))) === 'twelve', await order() ); + // As far right as it goes: the clamp stops the tab with its centre on the last tab's centre, + // which must still count as passing it. + await page.mouse.move(await centre(14), 22); + await page.mouse.down(); + await page.mouse.move((await centre(11)) + 400, 22, { steps: 12 }); + await page.mouse.up(); + check('dragged past the end, a tab lands in the last place', same(await take(), [{ cmd: 'move', id: 14, to: 3 }])); + check('and shows there', same(await order(), [12, 13, 11, 14]), await order()); // 8. Many tabs and long names. const many = Array.from({ length: 30 }, (_, i) => tab(100 + i, 'server-' + i, { active: i === 0 }));