From ff4a499ab76706bb449170232d57acb1a4f596eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 30 Oct 2026 04:41:20 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20the=20repo=20home's=20file?= =?UTF-8?q?=20tree=20and=20README=20are=20split=20by=20a=20handle=20the=20?= =?UTF-8?q?reader=20drags=20to=20widen=20or=20narrow=20the=20tree=20(arrow?= =?UTF-8?q?=20keys=20move=20it,=20Shift=20by=20more;=20Home=20or=20a=20dou?= =?UTF-8?q?ble=20click=20resets=20it);=20the=20width=20is=20kept=20in=20th?= =?UTF-8?q?e=20browser=20and=20applied=20on=20every=20repo=20home,=20clamp?= =?UTF-8?q?ed=20so=20the=20README=20keeps=20at=20least=20360px?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/forge-web/assets/nav.js | 123 +++++++++++++++++++++++++++++ crates/forge-web/src/pages/repo.rs | 3 + style/_repo.scss | 56 ++++++++++++- 3 files changed, 178 insertions(+), 4 deletions(-) diff --git a/crates/forge-web/assets/nav.js b/crates/forge-web/assets/nav.js index 915127f..8b514dc 100644 --- a/crates/forge-web/assets/nav.js +++ b/crates/forge-web/assets/nav.js @@ -800,6 +800,129 @@ }); }); + // Repo home resize: a drag on the separator between the file tree and the README sets the tree's + // width, the --tree-w property of the .repo-home grid. The width is kept in localStorage and applied + // to each repo home on load and after every swap. The README takes the rest of the row. + var TREE_KEY = 'forge-tree-w'; + var TREE_MIN = 220; // px, the narrowest the tree goes + var README_MIN = 360; // px, room the drag always leaves for the README + var TREE_STEP = 16; // px per arrow key; Shift moves 64px + var treeDrag = null; // { grid, id, x, w, moved } while a pointer drag runs + + function treeLoad() { + try { return parseFloat(localStorage.getItem(TREE_KEY)) || 0; } catch (err) { return 0; } + } + + function treeStore(px) { + try { + if (px) { localStorage.setItem(TREE_KEY, String(Math.round(px))); } else { localStorage.removeItem(TREE_KEY); } + } catch (err) { } + } + + // The widest the tree can be: the grid less the splitter, the two gaps, the README's minimum and, + // at 1200px and up, the aside's column with its gap. + function treeMax(grid) { + var split = grid.querySelector('[data-repo-split]'); + var side = grid.querySelector(':scope > .repo-meta'); + var readme = grid.querySelector('.repo-readme'); + var cs = getComputedStyle(grid); + var gap = parseFloat(cs.columnGap) || 0; + var inRow = side && readme && side.getBoundingClientRect().left > readme.getBoundingClientRect().left; + var aside = inRow ? side.getBoundingClientRect().width + gap + (parseFloat(getComputedStyle(side).marginLeft) || 0) : 0; + var max = grid.getBoundingClientRect().width - split.getBoundingClientRect().width - 2 * gap - aside - README_MIN; + return Math.max(TREE_MIN, Math.floor(max)); + } + + // Sets the tree width (clamped) and keeps the separator's aria values in step with it. + function treeSet(grid, px) { + var split = grid.querySelector('[data-repo-split]'); + var max = treeMax(grid); + var w = Math.min(max, Math.max(TREE_MIN, Math.round(px))); + grid.style.setProperty('--tree-w', w + 'px'); + split.setAttribute('aria-valuemin', String(TREE_MIN)); + split.setAttribute('aria-valuemax', String(max)); + split.setAttribute('aria-valuenow', String(w)); + return w; + } + + function treeWidth(grid) { + return grid.querySelector('.repo-main').getBoundingClientRect().width; + } + + // Applies the stored width to one repo home (or the default when none is stored). Below 900px the + // splitter is hidden and the columns stack, so there is nothing to set. + function treeApply(grid) { + var split = grid && grid.querySelector('[data-repo-split]'); + if (!split || getComputedStyle(split).display === 'none') { return; } + var saved = treeLoad(); + if (saved) { treeSet(grid, saved); return; } + grid.style.removeProperty('--tree-w'); + split.setAttribute('aria-valuemin', String(TREE_MIN)); + split.setAttribute('aria-valuemax', String(treeMax(grid))); + split.setAttribute('aria-valuenow', String(Math.round(treeWidth(grid)))); + } + + function treeApplyAll() { + document.querySelectorAll('.repo-home').forEach(treeApply); + } + + treeApplyAll(); + document.addEventListener('forge:swapped', treeApplyAll); + + document.addEventListener('pointerdown', function (e) { + var split = e.target.closest && e.target.closest('[data-repo-split]'); + var grid = split && split.closest('.repo-home'); + if (!grid || e.button !== 0 || getComputedStyle(split).display === 'none') { return; } + e.preventDefault(); + split.setPointerCapture(e.pointerId); + treeDrag = { grid: grid, id: e.pointerId, x: e.clientX, w: treeWidth(grid), moved: false }; + root.classList.add('tree-resizing'); + }); + + document.addEventListener('pointermove', function (e) { + if (!treeDrag || e.pointerId !== treeDrag.id) { return; } + if (e.clientX !== treeDrag.x) { treeDrag.moved = true; } + treeSet(treeDrag.grid, treeDrag.w + e.clientX - treeDrag.x); + }); + + function treeEnd(e) { + if (!treeDrag || e.pointerId !== treeDrag.id) { return; } + var drag = treeDrag; + treeDrag = null; + root.classList.remove('tree-resizing'); + if (drag.moved) { treeStore(treeWidth(drag.grid)); } + } + document.addEventListener('pointerup', treeEnd); + document.addEventListener('pointercancel', treeEnd); + + // Double-click resets the split to the default. + document.addEventListener('dblclick', function (e) { + var split = e.target.closest && e.target.closest('[data-repo-split]'); + var grid = split && split.closest('.repo-home'); + if (!grid) { return; } + grid.style.removeProperty('--tree-w'); + treeStore(null); + treeApply(grid); + }); + + // Arrow keys move the separator; Home resets it. + document.addEventListener('keydown', function (e) { + var split = e.target.closest && e.target.closest('[data-repo-split]'); + var grid = split && split.closest('.repo-home'); + if (!grid) { return; } + if (e.key === 'Home') { + grid.style.removeProperty('--tree-w'); + treeStore(null); + treeApply(grid); + } else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') { + var step = e.shiftKey ? 64 : TREE_STEP; + treeStore(treeSet(grid, treeWidth(grid) + (e.key === 'ArrowRight' ? step : -step))); + } else { + return; + } + e.preventDefault(); + }); + // Escape closes the open dropdowns and returns focus to the summary of the one that held it. document.addEventListener('keydown', function (e) { if (e.key !== 'Escape') { return; } diff --git a/crates/forge-web/src/pages/repo.rs b/crates/forge-web/src/pages/repo.rs index 6f7c5f6..94ae69f 100644 --- a/crates/forge-web/src/pages/repo.rs +++ b/crates/forge-web/src/pages/repo.rs @@ -513,6 +513,9 @@ async fn repo_page(cx: &Cx) -> Result { tree_table(rows: rows, latest: bar, lang: lang) +
if let Some(readme) = readme { readme_card(name: readme.name, markdown: readme.markdown, body: readme.body) diff --git a/style/_repo.scss b/style/_repo.scss index d020762..7959cfb 100644 --- a/style/_repo.scss +++ b/style/_repo.scss @@ -303,19 +303,65 @@ .readme { margin-top: 0; } + + // The drag handle between the tree and the README (nav.js drives it): a 1px rule centred in the + // 8px track, full height of the grid. Hidden below 900px, where the columns stack. + .repo-split { + display: none; + position: relative; + align-self: stretch; + cursor: col-resize; + touch-action: none; + outline: none; + + &::before { + content: ''; + position: absolute; + top: 0; + bottom: 0; + left: 50%; + width: 1px; + transform: translateX(-50%); + background: var(--border); + } + + &:hover::before, + &:focus-visible::before { + background: var(--accent); + } + + &:focus-visible::before { + width: 2px; + } + } +} + +// While a drag runs, the whole page keeps the resize cursor and the text stays unselected. +html.tree-resizing, +html.tree-resizing * { + cursor: col-resize !important; + user-select: none; +} + +html.tree-resizing .repo-split::before { + background: var(--accent); } // 900px to 1199px: the tree and README sit side by side and the aside drops under them at full // width, so the columns keep their own height and the aside flows with the page. @media (min-width: 900px) { .repo-grid { - gap: 40px; + gap: 40px 16px; } .repo-home { - grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); + grid-template-columns: var(--tree-w, 380px) 8px minmax(0, 1fr); align-items: start; + .repo-split { + display: block; + } + .repo-main, .repo-readme { max-height: var(--repo-home-h); @@ -354,8 +400,8 @@ // 1200px and up: browse bar and tree | README | aside, all filling the viewport height. @media (min-width: 1200px) { .repo-home { - grid-template-columns: minmax(320px, 420px) minmax(0, 1fr) 260px; - gap: 32px; + grid-template-columns: var(--tree-w, 420px) 8px minmax(0, 1fr) 260px; + column-gap: 12px; align-items: stretch; height: var(--repo-home-h); @@ -364,10 +410,12 @@ max-height: none; } + // With the splitter's 12px gaps this keeps the README and aside 32px apart, as before. .repo-meta { grid-column: auto; min-height: 0; overflow-y: auto; + margin-left: 20px; } } }