Fix Settings segmented controls replaying thumb animations (#135)
* Fix segmented-control animation replay in settings Scope the sliding-thumb cache to each control instead of sharing it across controls with identical options. Keep an existing thumb in place during rapid clicks so CSS continues its transition from the current position; a newly rendered control starts from its own last selection. * Preserve thumb slide across control redraws
This commit is contained in:
+23
-10
@@ -2261,23 +2261,36 @@ $("#modal").onclick = (e) => { if (e.target === e.currentTarget) cancelEdit(); }
|
||||
// ---------- sliding thumb ----------
|
||||
// Pills (the nav, every segmented control) have one thumb that glides to the
|
||||
// selected option instead of each option lighting up on its own.
|
||||
const thumbs = new Map(); // pill key → where its thumb is, so a re-rendered pill takes over mid-slide
|
||||
const thumbs = new Map(); // control position → where a re-rendered thumb resumes its slide
|
||||
function thumbKey(box, choices) {
|
||||
const path = [];
|
||||
for (let node = box; node?.parentElement; node = node.parentElement) {
|
||||
if (node.id) return node.id + "/" + path.reverse().join("/") + ":" + choices;
|
||||
path.push(Array.prototype.indexOf.call(node.parentElement.children, node));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function slide(box, key) {
|
||||
let th = box.querySelector(":scope > .thumb");
|
||||
if (!th) { th = el("span", "thumb"); box.prepend(th); }
|
||||
const fresh = !th;
|
||||
if (fresh) { th = el("span", "thumb"); box.prepend(th); }
|
||||
const on = box.querySelector(":scope > .on");
|
||||
if (!on) { th.style.opacity = "0"; return; }
|
||||
th.style.opacity = "";
|
||||
const to = { x: on.offsetLeft, w: on.offsetWidth };
|
||||
const last = thumbs.get(key);
|
||||
const from = last && performance.now() - last.at < 300 ? last.from : last; // re-rendered mid-slide: start where the old one started
|
||||
const control = thumbKey(box, key);
|
||||
const last = control && thumbs.get(control);
|
||||
let from = to;
|
||||
const put = (p) => { th.style.transform = `translateX(${p.x}px)`; th.style.width = p.w + "px"; };
|
||||
th.classList.add("still");
|
||||
put(from || to);
|
||||
void th.offsetWidth;
|
||||
th.classList.remove("still");
|
||||
if (fresh) {
|
||||
from = last ? (performance.now() - last.at < 300 ? last.from : last) : to;
|
||||
th.classList.add("still");
|
||||
put(from);
|
||||
void th.offsetWidth;
|
||||
th.classList.remove("still");
|
||||
} else if (last) from = { x: last.x, w: last.w };
|
||||
put(to);
|
||||
thumbs.set(key, { ...to, at: performance.now(), from: from || to });
|
||||
if (control) thumbs.set(control, { ...to, from, at: performance.now() });
|
||||
}
|
||||
|
||||
const PROTOS = [["chat", "OpenAI", "Chat Completions — most agents"], ["responses", "Responses", "OpenAI Responses — what Codex speaks"], ["anthropic", "Anthropic", "Anthropic Messages — what Claude Code speaks"], ["decide", "Jev", "Jev's decision API (TypeSafe's, or a gateway's) — what a routing group asks as a turn begins"]];
|
||||
@@ -5426,7 +5439,7 @@ if (mode === "window") new ResizeObserver(() => {
|
||||
th.classList.add("still");
|
||||
th.style.transform = `translateX(${on.offsetLeft}px)`;
|
||||
th.style.width = on.offsetWidth + "px";
|
||||
thumbs.set("nav", { x: on.offsetLeft, w: on.offsetWidth, at: 0 });
|
||||
thumbs.set(thumbKey($("#nav"), "nav"), { x: on.offsetLeft, w: on.offsetWidth });
|
||||
requestAnimationFrame(() => th.classList.remove("still"));
|
||||
}).observe($("#nav"));
|
||||
document.fonts?.ready.then(fitTop);
|
||||
|
||||
Reference in New Issue
Block a user