2 files changed, +227, -37
1c28ceaKeep the tree bar on one row
author
mogi <git@paramogi.world> on 30-11-2026 01:34 UTC
committer
mogi <git@paramogi.world> on 30-11-2026 01:34 UTC
parentbd5ef6b
src/html.rs
+71, -18
style.css
+156, -19
+71, -18
        @@ -1497,8 +1497,9 @@ fn ref_bar(
14971497     commits: usize,
14981498     current: &str,
14991499 ) -> String {
1500    -    let mut bar =
1501    -        String::from("<div class=\"box sticky flex items-center gap flex-wrap ref-bar\">\n");
    1500+    let mut bar = String::from(
    1501+        "<div class=\"box sticky flex items-center gap flex-wrap ref-bar\">\n<div class=\"ref-main\">\n",
    1502+    );
15021503     bar.push_str(&ref_menu(
15031504         repo,
15041505         git_ref,
        @@ -1512,23 +1513,33 @@ fn ref_bar(
15121513         let tree_path = format!("{}/{part}", parts[parts.len() - 1].1);
15131514         parts.push((part, tree_path));
15141515     }
1515    -    for (i, (part, tree_path)) in parts.iter().enumerate() {
1516    -        if i > 0 {
1517    -            bar.push_str("<span>/</span>\n");
1518    -        }
1519    -        if i == parts.len() - 1 {
1520    -            bar.push_str(&format!(
1521    -                "<span class=\"font-bold\">{}</span>\n",
1522    -                escape_str(part)
1523    -            ));
1524    -        } else {
1525    -            bar.push_str(&format!(
1526    -                "<a href=\"{repo_root}{}\">{}</a>\n",
1527    -                Tab::Tree.href(tree_path),
1528    -                escape_str(part)
1529    -            ));
    1516+    let links: Vec<(String, String)> = parts
    1517+        .iter()
    1518+        .map(|(part, tree_path)| {
    1519+            (
    1520+                format!("{repo_root}{}", Tab::Tree.href(tree_path)),
    1521+                escape_str(part),
    1522+            )
    1523+        })
    1524+        .collect();
    1525+    if let [parents @ .., (_, name)] = links.as_slice() {
    1526+        let last = format!("<span class=\"font-bold\">{name}</span>\n");
    1527+        match parents {
    1528+            [] => bar.push_str(&last),
    1529+            [(href, repo_name), folders @ ..] => {
    1530+                bar.push_str(&format!(
    1531+                    "<a class=\"ref-repo\" href=\"{href}\">{}</a>\n<span>/</span>\n",
    1532+                    fit_name(repo_name)
    1533+                ));
    1534+                if folders.is_empty() {
    1535+                    bar.push_str(&last);
    1536+                } else {
    1537+                    write_path_layers(&mut bar, folders, &last);
    1538+                }
    1539+            }
15301540         }
15311541     }
    1542+    bar.push_str("</div>\n");
15321543     bar.push_str(&format!(
15331544         "<a class=\"ref-bar-commits\" href=\"{repo_root}{}\">{}</a>\n</div>\n",
15341545         Tab::Commits.href(&git_ref.dir),
        @@ -1537,6 +1548,44 @@ fn ref_bar(
15371548     bar
15381549 }
15391550 
    1551+fn write_path_layers(body: &mut String, folders: &[(String, String)], last: &str) {
    1552+    body.push_str("<div class=\"ref-path\">\n");
    1553+    for hidden in (0..=folders.len()).rev() {
    1554+        let mut crumbs = Vec::new();
    1555+        let tabindex = if hidden > 0 { " tabindex=\"-1\"" } else { "" };
    1556+        if let Some((href, name)) = folders[..hidden].last() {
    1557+            crumbs.push(format!(
    1558+                "<a{tabindex} href=\"{href}\" title=\"{name}\" aria-label=\"folders up to {name}\">…</a>\n"
    1559+            ));
    1560+        }
    1561+        for (href, name) in &folders[hidden..] {
    1562+            crumbs.push(format!("<a{tabindex} href=\"{href}\">{name}</a>\n"));
    1563+        }
    1564+        crumbs.push(last.to_string());
    1565+        let (class, strut) = if hidden == folders.len() {
    1566+            (" last", "")
    1567+        } else {
    1568+            ("", "<span class=\"ref-strut\"></span>\n")
    1569+        };
    1570+        let aria = if hidden > 0 {
    1571+            " aria-hidden=\"true\""
    1572+        } else {
    1573+            ""
    1574+        };
    1575+        body.push_str(&format!(
    1576+            "<div class=\"ref-layer{class}\"{aria}>\n{strut}<div class=\"ref-crumbs\">\n{}</div>\n</div>\n",
    1577+            crumbs.join("<span>/</span>\n")
    1578+        ));
    1579+    }
    1580+    body.push_str("</div>\n");
    1581+}
    1582+
    1583+fn fit_name(name: &str) -> String {
    1584+    format!(
    1585+        "<span class=\"fit-name\"><span class=\"fit-full\"><i>&#8203;</i><span>{name}</span></span><span class=\"fit-cut\" aria-hidden=\"true\"><span class=\"truncate\">{name}</span><span class=\"fit-dots\">…</span></span></span>"
    1586+    )
    1587+}
    1588+
15401589 fn commit_count(commits: usize) -> String {
15411590     let s = if commits == 1 { "" } else { "s" };
15421591     format!("<span class=\"font-bold\">{commits}</span> commit{s}")
        @@ -1562,10 +1611,14 @@ fn ref_menu(
15621611     current: &str,
15631612 ) -> String {
15641613     let name = escape_str(&git_ref.name);
    1614+    let label = match tab {
    1615+        Tab::Tree => fit_name(&name),
    1616+        _ => format!("<span class=\"truncate\">{name}</span>"),
    1617+    };
15651618     let mut menu = format!(
15661619         "\
15671620 <div class=\"ref-menu\">\n\
1568    -<button type=\"button\" class=\"ref-btn\" popovertarget=\"ref-menu\" aria-label=\"{name}, switch branch or tag\">{}<span class=\"truncate\">{name}</span>{}{}</button>\n\
    1621+<button type=\"button\" class=\"ref-btn\" popovertarget=\"ref-menu\" aria-label=\"{name}, switch branch or tag\">{}{label}{}{}</button>\n\
15691622 <div class=\"ref-menu-list\" id=\"ref-menu\" popover>\n\
15701623 ",
15711624         ref_icon(git_ref),
+156, -19
        @@ -245,6 +245,7 @@ label {
 245 245   font-size: var(--text-base);
 246 246   color: inherit;
 247 247   background-color: var(--code);
     248+  --fit-bg: var(--code);
 248 249 }
 249 250 
 250 251 .ref-btn svg {
        @@ -278,6 +279,7 @@ label {
 278 279 .ref-btn:hover,
 279 280 .ref-menu:has(> :popover-open) > .ref-btn {
 280 281   background-color: var(--active);
     282+  --fit-bg: var(--active);
 281 283 }
 282 284 
 283 285 .ref-btn svg:nth-last-child(-n + 2) {
        @@ -606,7 +608,7 @@ main {
 606 608   min-width: 0;
 607 609   height: calc(1lh + 0.3rem + 2px);
 608 610   row-gap: 2rem;
 609    -  overflow: hidden;
     611+  overflow: clip;
 610 612   font-size: var(--text-sm);
 611 613 }
 612 614 
        @@ -1692,45 +1694,180 @@ pre.chroma[style] .cl {
16921694   }
16931695 }
16941696 
1695    -.ref-bar > span:not([class]) {
1696    -  color: var(--muted);
1697    -}
1698    -
16991697 .ref-bar {
1700    -  flex-wrap: nowrap;
    1698+  flex-wrap: wrap;
    1699+  align-content: flex-start;
    1700+  height: 2.725rem;
    1701+  row-gap: 3rem;
    1702+  overflow: clip;
17011703   white-space: nowrap;
    1704+  --fit-bg: var(--surface);
    1705+}
    1706+
    1707+.ref-bar,
    1708+.ref-main,
    1709+.ref-crumbs {
    1710+  column-gap: 0.5rem;
    1711+}
    1712+
    1713+.ref-main {
    1714+  display: flex;
    1715+  flex: 0 1 auto;
    1716+  align-items: center;
    1717+  min-width: 0;
17021718 }
17031719 
1704    -.ref-bar > :is(a, span) {
    1720+.ref-main > :is(a, span) {
17051721   min-width: 0;
17061722   overflow: hidden;
17071723   text-overflow: ellipsis;
17081724 }
17091725 
1710    -.ref-bar > a:not(.ref-bar-commits) {
1711    -  flex-shrink: 100;
1712    -  min-width: 1.5em;
    1726+:is(.ref-main, .ref-crumbs) > span:not([class]) {
    1727+  flex-shrink: 0;
    1728+  color: var(--muted);
17131729 }
17141730 
1715    -.ref-bar > :is(.ref-bar-commits, span:not([class])) {
1716    -  flex-shrink: 0;
    1731+.ref-main > .ref-menu {
    1732+  flex: 0 1 auto;
    1733+  min-width: min-content;
    1734+  max-width: max(35%, 6.5rem, min(32rem, 100% - 20rem));
    1735+}
    1736+
    1737+.ref-main > a.ref-repo {
    1738+  flex: 0 1000000 auto;
    1739+  min-width: 1.2em;
    1740+}
    1741+
    1742+.ref-main > .ref-path {
    1743+  display: grid;
    1744+  flex: 0 1000000000000 auto;
    1745+  grid-template-columns: minmax(0, 1fr);
    1746+  min-width: 4.2rem;
    1747+}
    1748+
    1749+.ref-main > .font-bold {
    1750+  flex: 0 1000000000000 auto;
    1751+  min-width: 1.9em;
    1752+}
    1753+
    1754+.ref-layer {
    1755+  display: flex;
    1756+  flex-wrap: wrap;
    1757+  grid-area: 1 / 1;
    1758+  min-width: 0;
    1759+  height: 1lh;
    1760+  overflow: clip;
    1761+  pointer-events: none;
    1762+}
    1763+
    1764+.ref-strut {
    1765+  width: 0;
    1766+  height: 1lh;
    1767+}
    1768+
    1769+.ref-crumbs {
    1770+  display: flex;
    1771+  flex: 1 0 auto;
    1772+  height: 1lh;
    1773+  background: var(--surface);
    1774+  pointer-events: auto;
    1775+}
    1776+
    1777+.ref-layer.last {
    1778+  flex-wrap: nowrap;
    1779+}
    1780+
    1781+.ref-layer.last > .ref-crumbs {
    1782+  flex: 1 1 0;
    1783+  min-width: 0;
    1784+}
    1785+
    1786+.ref-layer.last > .ref-crumbs > .font-bold {
    1787+  min-width: 0;
    1788+  overflow: hidden;
    1789+  text-overflow: ellipsis;
17171790 }
17181791 
17191792 .ref-bar-commits {
    1793+  flex-shrink: 0;
17201794   margin-left: auto;
17211795 }
17221796 
1723    -@media only screen and (max-width: 600px) {
1724    -  .ref-bar {
1725    -    flex-wrap: wrap;
1726    -    white-space: normal;
    1797+.fit-name {
    1798+  position: relative;
    1799+  display: grid;
    1800+  grid-template-columns: minmax(0, 1fr);
    1801+  min-width: 1.2em;
    1802+}
    1803+
    1804+.fit-full {
    1805+  position: relative;
    1806+  z-index: 1;
    1807+  display: flex;
    1808+  flex-wrap: wrap;
    1809+  align-items: baseline;
    1810+  grid-area: 1 / 1;
    1811+  min-width: 0;
    1812+  height: 1lh;
    1813+  overflow: clip;
    1814+}
    1815+
    1816+.fit-full > i {
    1817+  width: 0;
    1818+  height: 1lh;
    1819+  font-style: normal;
    1820+}
    1821+
    1822+.fit-full > span {
    1823+  flex: 1 0 auto;
    1824+  height: 1lh;
    1825+  white-space: nowrap;
    1826+  background-color: var(--fit-bg);
    1827+  transition: background-color 0.12s;
    1828+}
    1829+
    1830+.fit-cut {
    1831+  grid-area: 1 / 1;
    1832+  min-width: 0;
    1833+  height: 1lh;
    1834+  container-type: inline-size;
    1835+}
    1836+
    1837+.fit-cut > span {
    1838+  display: block;
    1839+  overflow: clip;
    1840+  text-overflow: ellipsis;
    1841+  white-space: nowrap;
    1842+}
    1843+
    1844+.fit-cut > .fit-dots {
    1845+  display: none;
    1846+}
    1847+
    1848+@container (width < 1.9em) {
    1849+  .fit-cut > .truncate {
    1850+    display: none;
17271851   }
17281852 
1729    -  .ref-bar > :is(a, span) {
1730    -    overflow: visible;
1731    -    overflow-wrap: anywhere;
    1853+  .fit-cut > .fit-dots {
    1854+    display: block;
    1855+  }
    1856+}
    1857+
    1858+@media (max-width: 359px) {
    1859+  .ref-bar,
    1860+  .ref-main,
    1861+  .ref-crumbs {
    1862+    column-gap: 0.35rem;
    1863+  }
    1864+
    1865+  .ref-bar .ref-btn {
    1866+    padding-inline: 0.35rem;
17321867   }
    1868+}
17331869 
    1870+@media only screen and (max-width: 600px) {
17341871   .ref-bar.sticky {
17351872     position: static;
17361873   }