The repo home's file tree and README are split by a handle the reader drags to widen or narrow the tree (arrow keys move it, Shift by more
Browse files at this commitff4a499ab76706bb449170232d57acb1a4f596ebParent: 240478f- feat
- the repo home's file tree and README are split by a handle the reader drags to widen or narrow the tree (arrow keys move it, Shift by more
- Home or a double click resets it)
- the width is kept in the browser and applied on every repo home, clamped so the README keeps at least 360px
3 changed files +178 -4
- crates/forge-web/assets/nav.js +123 -0
- crates/forge-web/src/pages/repo.rs +3 -0
- style/_repo.scss +52 -4
crates/forge-web/assets/nav.jsmodified+123 -0
| @@ -800,6 +800,129 @@ | ||
| 800 | 800 | }); |
| 801 | 801 | }); |
| 802 | 802 | |
| 803 | + // Repo home resize: a drag on the separator between the file tree and the README sets the tree's | |
| 804 | + // width, the --tree-w property of the .repo-home grid. The width is kept in localStorage and applied | |
| 805 | + // to each repo home on load and after every swap. The README takes the rest of the row. | |
| 806 | + var TREE_KEY = 'forge-tree-w'; | |
| 807 | + var TREE_MIN = 220; // px, the narrowest the tree goes | |
| 808 | + var README_MIN = 360; // px, room the drag always leaves for the README | |
| 809 | + var TREE_STEP = 16; // px per arrow key; Shift moves 64px | |
| 810 | + var treeDrag = null; // { grid, id, x, w, moved } while a pointer drag runs | |
| 811 | + | |
| 812 | + function treeLoad() { | |
| 813 | + try { return parseFloat(localStorage.getItem(TREE_KEY)) || 0; } catch (err) { return 0; } | |
| 814 | + } | |
| 815 | + | |
| 816 | + function treeStore(px) { | |
| 817 | + try { | |
| 818 | + if (px) { localStorage.setItem(TREE_KEY, String(Math.round(px))); } else { localStorage.removeItem(TREE_KEY); } | |
| 819 | + } catch (err) { } | |
| 820 | + } | |
| 821 | + | |
| 822 | + // The widest the tree can be: the grid less the splitter, the two gaps, the README's minimum and, | |
| 823 | + // at 1200px and up, the aside's column with its gap. | |
| 824 | + function treeMax(grid) { | |
| 825 | + var split = grid.querySelector('[data-repo-split]'); | |
| 826 | + var side = grid.querySelector(':scope > .repo-meta'); | |
| 827 | + var readme = grid.querySelector('.repo-readme'); | |
| 828 | + var cs = getComputedStyle(grid); | |
| 829 | + var gap = parseFloat(cs.columnGap) || 0; | |
| 830 | + var inRow = side && readme && side.getBoundingClientRect().left > readme.getBoundingClientRect().left; | |
| 831 | + var aside = inRow ? side.getBoundingClientRect().width + gap + (parseFloat(getComputedStyle(side).marginLeft) || 0) : 0; | |
| 832 | + var max = grid.getBoundingClientRect().width - split.getBoundingClientRect().width - 2 * gap - aside - README_MIN; | |
| 833 | + return Math.max(TREE_MIN, Math.floor(max)); | |
| 834 | + } | |
| 835 | + | |
| 836 | + // Sets the tree width (clamped) and keeps the separator's aria values in step with it. | |
| 837 | + function treeSet(grid, px) { | |
| 838 | + var split = grid.querySelector('[data-repo-split]'); | |
| 839 | + var max = treeMax(grid); | |
| 840 | + var w = Math.min(max, Math.max(TREE_MIN, Math.round(px))); | |
| 841 | + grid.style.setProperty('--tree-w', w + 'px'); | |
| 842 | + split.setAttribute('aria-valuemin', String(TREE_MIN)); | |
| 843 | + split.setAttribute('aria-valuemax', String(max)); | |
| 844 | + split.setAttribute('aria-valuenow', String(w)); | |
| 845 | + return w; | |
| 846 | + } | |
| 847 | + | |
| 848 | + function treeWidth(grid) { | |
| 849 | + return grid.querySelector('.repo-main').getBoundingClientRect().width; | |
| 850 | + } | |
| 851 | + | |
| 852 | + // Applies the stored width to one repo home (or the default when none is stored). Below 900px the | |
| 853 | + // splitter is hidden and the columns stack, so there is nothing to set. | |
| 854 | + function treeApply(grid) { | |
| 855 | + var split = grid && grid.querySelector('[data-repo-split]'); | |
| 856 | + if (!split || getComputedStyle(split).display === 'none') { return; } | |
| 857 | + var saved = treeLoad(); | |
| 858 | + if (saved) { treeSet(grid, saved); return; } | |
| 859 | + grid.style.removeProperty('--tree-w'); | |
| 860 | + split.setAttribute('aria-valuemin', String(TREE_MIN)); | |
| 861 | + split.setAttribute('aria-valuemax', String(treeMax(grid))); | |
| 862 | + split.setAttribute('aria-valuenow', String(Math.round(treeWidth(grid)))); | |
| 863 | + } | |
| 864 | + | |
| 865 | + function treeApplyAll() { | |
| 866 | + document.querySelectorAll('.repo-home').forEach(treeApply); | |
| 867 | + } | |
| 868 | + | |
| 869 | + treeApplyAll(); | |
| 870 | + document.addEventListener('forge:swapped', treeApplyAll); | |
| 871 | + | |
| 872 | + document.addEventListener('pointerdown', function (e) { | |
| 873 | + var split = e.target.closest && e.target.closest('[data-repo-split]'); | |
| 874 | + var grid = split && split.closest('.repo-home'); | |
| 875 | + if (!grid || e.button !== 0 || getComputedStyle(split).display === 'none') { return; } | |
| 876 | + e.preventDefault(); | |
| 877 | + split.setPointerCapture(e.pointerId); | |
| 878 | + treeDrag = { grid: grid, id: e.pointerId, x: e.clientX, w: treeWidth(grid), moved: false }; | |
| 879 | + root.classList.add('tree-resizing'); | |
| 880 | + }); | |
| 881 | + | |
| 882 | + document.addEventListener('pointermove', function (e) { | |
| 883 | + if (!treeDrag || e.pointerId !== treeDrag.id) { return; } | |
| 884 | + if (e.clientX !== treeDrag.x) { treeDrag.moved = true; } | |
| 885 | + treeSet(treeDrag.grid, treeDrag.w + e.clientX - treeDrag.x); | |
| 886 | + }); | |
| 887 | + | |
| 888 | + function treeEnd(e) { | |
| 889 | + if (!treeDrag || e.pointerId !== treeDrag.id) { return; } | |
| 890 | + var drag = treeDrag; | |
| 891 | + treeDrag = null; | |
| 892 | + root.classList.remove('tree-resizing'); | |
| 893 | + if (drag.moved) { treeStore(treeWidth(drag.grid)); } | |
| 894 | + } | |
| 895 | + document.addEventListener('pointerup', treeEnd); | |
| 896 | + document.addEventListener('pointercancel', treeEnd); | |
| 897 | + | |
| 898 | + // Double-click resets the split to the default. | |
| 899 | + document.addEventListener('dblclick', function (e) { | |
| 900 | + var split = e.target.closest && e.target.closest('[data-repo-split]'); | |
| 901 | + var grid = split && split.closest('.repo-home'); | |
| 902 | + if (!grid) { return; } | |
| 903 | + grid.style.removeProperty('--tree-w'); | |
| 904 | + treeStore(null); | |
| 905 | + treeApply(grid); | |
| 906 | + }); | |
| 907 | + | |
| 908 | + // Arrow keys move the separator; Home resets it. | |
| 909 | + document.addEventListener('keydown', function (e) { | |
| 910 | + var split = e.target.closest && e.target.closest('[data-repo-split]'); | |
| 911 | + var grid = split && split.closest('.repo-home'); | |
| 912 | + if (!grid) { return; } | |
| 913 | + if (e.key === 'Home') { | |
| 914 | + grid.style.removeProperty('--tree-w'); | |
| 915 | + treeStore(null); | |
| 916 | + treeApply(grid); | |
| 917 | + } else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') { | |
| 918 | + var step = e.shiftKey ? 64 : TREE_STEP; | |
| 919 | + treeStore(treeSet(grid, treeWidth(grid) + (e.key === 'ArrowRight' ? step : -step))); | |
| 920 | + } else { | |
| 921 | + return; | |
| 922 | + } | |
| 923 | + e.preventDefault(); | |
| 924 | + }); | |
| 925 | + | |
| 803 | 926 | // Escape closes the open dropdowns and returns focus to the summary of the one that held it. |
| 804 | 927 | document.addEventListener('keydown', function (e) { |
| 805 | 928 | if (e.key !== 'Escape') { return; } |
crates/forge-web/src/pages/repo.rsmodified+3 -0
| @@ -513,6 +513,9 @@ async fn repo_page(cx: &Cx) -> Result<impl View> { | ||
| 513 | 513 | </div> |
| 514 | 514 | tree_table(rows: rows, latest: bar, lang: lang) |
| 515 | 515 | </div> |
| 516 | + <div class="repo-split" role="separator" aria-orientation="vertical" | |
| 517 | + aria-label=(s(lang, "Resize file tree", "Dosya ağacını boyutlandır")) tabindex="0" | |
| 518 | + data-repo-split=""></div> | |
| 516 | 519 | <div class="repo-readme"> |
| 517 | 520 | if let Some(readme) = readme { |
| 518 | 521 | readme_card(name: readme.name, markdown: readme.markdown, body: readme.body) |
style/_repo.scssmodified+52 -4
| @@ -303,19 +303,65 @@ | ||
| 303 | 303 | .readme { |
| 304 | 304 | margin-top: 0; |
| 305 | 305 | } |
| 306 | + | |
| 307 | + // The drag handle between the tree and the README (nav.js drives it): a 1px rule centred in the | |
| 308 | + // 8px track, full height of the grid. Hidden below 900px, where the columns stack. | |
| 309 | + .repo-split { | |
| 310 | + display: none; | |
| 311 | + position: relative; | |
| 312 | + align-self: stretch; | |
| 313 | + cursor: col-resize; | |
| 314 | + touch-action: none; | |
| 315 | + outline: none; | |
| 316 | + | |
| 317 | + &::before { | |
| 318 | + content: ''; | |
| 319 | + position: absolute; | |
| 320 | + top: 0; | |
| 321 | + bottom: 0; | |
| 322 | + left: 50%; | |
| 323 | + width: 1px; | |
| 324 | + transform: translateX(-50%); | |
| 325 | + background: var(--border); | |
| 326 | + } | |
| 327 | + | |
| 328 | + &:hover::before, | |
| 329 | + &:focus-visible::before { | |
| 330 | + background: var(--accent); | |
| 331 | + } | |
| 332 | + | |
| 333 | + &:focus-visible::before { | |
| 334 | + width: 2px; | |
| 335 | + } | |
| 336 | + } | |
| 337 | +} | |
| 338 | + | |
| 339 | +// While a drag runs, the whole page keeps the resize cursor and the text stays unselected. | |
| 340 | +html.tree-resizing, | |
| 341 | +html.tree-resizing * { | |
| 342 | + cursor: col-resize !important; | |
| 343 | + user-select: none; | |
| 344 | +} | |
| 345 | + | |
| 346 | +html.tree-resizing .repo-split::before { | |
| 347 | + background: var(--accent); | |
| 306 | 348 | } |
| 307 | 349 | |
| 308 | 350 | // 900px to 1199px: the tree and README sit side by side and the aside drops under them at full |
| 309 | 351 | // width, so the columns keep their own height and the aside flows with the page. |
| 310 | 352 | @media (min-width: 900px) { |
| 311 | 353 | .repo-grid { |
| 312 | - gap: 40px; | |
| 354 | + gap: 40px 16px; | |
| 313 | 355 | } |
| 314 | 356 | |
| 315 | 357 | .repo-home { |
| 316 | - grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); | |
| 358 | + grid-template-columns: var(--tree-w, 380px) 8px minmax(0, 1fr); | |
| 317 | 359 | align-items: start; |
| 318 | 360 | |
| 361 | + .repo-split { | |
| 362 | + display: block; | |
| 363 | + } | |
| 364 | + | |
| 319 | 365 | .repo-main, |
| 320 | 366 | .repo-readme { |
| 321 | 367 | max-height: var(--repo-home-h); |
| @@ -354,8 +400,8 @@ | ||
| 354 | 400 | // 1200px and up: browse bar and tree | README | aside, all filling the viewport height. |
| 355 | 401 | @media (min-width: 1200px) { |
| 356 | 402 | .repo-home { |
| 357 | - grid-template-columns: minmax(320px, 420px) minmax(0, 1fr) 260px; | |
| 358 | - gap: 32px; | |
| 403 | + grid-template-columns: var(--tree-w, 420px) 8px minmax(0, 1fr) 260px; | |
| 404 | + column-gap: 12px; | |
| 359 | 405 | align-items: stretch; |
| 360 | 406 | height: var(--repo-home-h); |
| 361 | 407 | |
| @@ -364,10 +410,12 @@ | ||
| 364 | 410 | max-height: none; |
| 365 | 411 | } |
| 366 | 412 | |
| 413 | + // With the splitter's 12px gaps this keeps the README and aside 32px apart, as before. | |
| 367 | 414 | .repo-meta { |
| 368 | 415 | grid-column: auto; |
| 369 | 416 | min-height: 0; |
| 370 | 417 | overflow-y: auto; |
| 418 | + margin-left: 20px; | |
| 371 | 419 | } |
| 372 | 420 | } |
| 373 | 421 | } |