Add drag-resizable sidebar/chat separator to the web GUI
Desktop-only (>=900px) pointer-drag splitter between the session list and the chat; width clamped (200px..min(480, 50% viewport)) and persisted in localStorage; keyboard arrows + ARIA separator role; hover/focus highlight. README updated. Web assets only; suite unchanged (94 green + 2 ignored), clippy/fmt clean.
This commit is contained in:
1 parent
1e13caa4ed
commit
e29878bb3d
4 files changed
+67
-2
No files matched your search
@@ -236,7 +236,55 @@ function autoGrow(t) {
|
||||
t.style.height = Math.min(t.scrollHeight, window.innerHeight * 0.4) + "px";
|
||||
}
|
||||
|
||||
// ---- Resizable sidebar/chat separator (desktop only) ----------------------
|
||||
function initSplitter() {
|
||||
const splitter = $("#splitter");
|
||||
const root = document.documentElement;
|
||||
const width = () =>
|
||||
parseInt(getComputedStyle(root).getPropertyValue("--sidebar-w")) || 280;
|
||||
const apply = (w) => {
|
||||
const max = Math.min(480, Math.floor(window.innerWidth * 0.5));
|
||||
w = Math.max(200, Math.min(max, w));
|
||||
root.style.setProperty("--sidebar-w", w + "px");
|
||||
splitter.setAttribute("aria-valuenow", String(w));
|
||||
return w;
|
||||
};
|
||||
const save = () => {
|
||||
try { localStorage.setItem("sidebarW", String(width())); } catch { /* private mode */ }
|
||||
};
|
||||
|
||||
let dragging = false, startX = 0, startW = 0;
|
||||
splitter.addEventListener("pointerdown", (e) => {
|
||||
dragging = true; startX = e.clientX; startW = width();
|
||||
splitter.setPointerCapture(e.pointerId);
|
||||
document.body.classList.add("resizing");
|
||||
e.preventDefault();
|
||||
});
|
||||
splitter.addEventListener("pointermove", (e) => {
|
||||
if (dragging) apply(startW + (e.clientX - startX));
|
||||
});
|
||||
const end = () => {
|
||||
if (!dragging) return;
|
||||
dragging = false;
|
||||
document.body.classList.remove("resizing");
|
||||
save();
|
||||
};
|
||||
splitter.addEventListener("pointerup", end);
|
||||
splitter.addEventListener("pointercancel", end);
|
||||
splitter.addEventListener("keydown", (e) => {
|
||||
if (e.key === "ArrowLeft") apply(width() - 16);
|
||||
else if (e.key === "ArrowRight") apply(width() + 16);
|
||||
else return;
|
||||
e.preventDefault(); save();
|
||||
});
|
||||
try {
|
||||
const w = localStorage.getItem("sidebarW");
|
||||
if (w) apply(parseInt(w));
|
||||
} catch { /* private mode */ }
|
||||
}
|
||||
|
||||
function wire() {
|
||||
initSplitter();
|
||||
$("#menu").addEventListener("click", openDrawer);
|
||||
$("#scrim").addEventListener("click", closeDrawer);
|
||||
$("#new-session").addEventListener("click", newSession);
|
||||
|
||||
Reference in new issue
Block a user