From 749adabe20dce7a519ab04ab9dd713e97ca5e6ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 27 Oct 2026 04:17:30 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20style:=20branch=20picker=20is=20?= =?UTF-8?q?a=20command=20palette:=20one=20searchable=20list=20with=20Branc?= =?UTF-8?q?hes=20and=20Tags=20sections,=20tip=20ages,=20a=20default=20chip?= =?UTF-8?q?=20and=20key=20hints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/forge-web/assets/nav.js | 89 +++++----- crates/forge-web/src/pages/refs.rs | 1 + crates/forge-web/src/views/mod.rs | 106 +++++++----- style/main.scss | 267 ++++++++++++++++++----------- 4 files changed, 279 insertions(+), 184 deletions(-) diff --git a/crates/forge-web/assets/nav.js b/crates/forge-web/assets/nav.js index 3882dab..932101e 100644 --- a/crates/forge-web/assets/nav.js +++ b/crates/forge-web/assets/nav.js @@ -2053,54 +2053,65 @@ }, false); // ---- branch switcher ------------------------------------------------------------------------ - // The ref popover in the browse bar: a filter over the active list, Branches and Tags tabs, and - // arrow keys through the visible entries as in the file finder. Entries past the first REF_SHOWN - // stay hidden until the filter narrows them, so the filter still reaches every name. + // The ref popover in the browse bar: one filter over a Branches and a Tags section, the matched + // part of each name marked, and arrow keys (or the pointer) through the visible entries as in the + // file finder. Entries past the first REF_SHOWN of a section stay hidden until the filter narrows + // them, so the filter still reaches every name. - var REF_SHOWN = 10; + var REF_SHOWN = 8; function refSwitchOf(el) { return el && el.closest ? el.closest('details[data-ref-switch]') : null; } - function refPanelOf(sw) { - var tab = sw.querySelector('[data-ref-tab][aria-selected="true"]'); - var kind = tab ? tab.getAttribute('data-ref-tab') : 'branches'; - return sw.querySelector('[data-ref-panel="' + kind + '"]'); - } - - function refShown(panel) { - return Array.prototype.filter.call(panel.querySelectorAll('[data-ref-item]'), function (li) { + function refShown(sw) { + return Array.prototype.filter.call(sw.querySelectorAll('[data-ref-item]'), function (li) { return !li.hidden; }); } - // Applies the filter to the active panel: every match, or the first entries when it is empty. + // Writes `name` into `el`, the first case-insensitive match of `q` wrapped in . + function refMark(el, name, q) { + var at = q ? name.toLowerCase().indexOf(q) : -1; + el.textContent = ''; + if (at < 0) { el.textContent = name; return; } + var mark = document.createElement('mark'); + mark.textContent = name.slice(at, at + q.length); + el.append(name.slice(0, at), mark, name.slice(at + q.length)); + } + + // Applies the filter to every section: each match, or the first entries when it is empty. A + // section with nothing to show hides with its heading. function refApply(sw) { var q = sw.querySelector('[data-ref-filter]').value.trim().toLowerCase(); - var panel = refPanelOf(sw); - var empty = panel.querySelector('[data-ref-empty]'); - var shown = 0; - Array.prototype.forEach.call(panel.querySelectorAll('[data-ref-item]'), function (li, i) { - var show = q ? li.textContent.trim().toLowerCase().indexOf(q) >= 0 : i < REF_SHOWN; - li.hidden = !show; - li.removeAttribute('aria-selected'); - if (show) { shown++; } + var groups = sw.querySelectorAll('[data-ref-group]'); + var total = 0; + groups.forEach(function (group) { + var shown = 0; + group.querySelectorAll('[data-ref-item]').forEach(function (li, i) { + var name = li.getAttribute('data-ref-name') || ''; + var show = q ? name.toLowerCase().indexOf(q) >= 0 : i < REF_SHOWN; + li.hidden = !show; + li.removeAttribute('aria-selected'); + if (show) { shown++; refMark(li.querySelector('.ref-text'), name, q); } + }); + group.hidden = shown === 0; + total += shown; }); - if (empty) { empty.hidden = shown > 0; } + var empty = sw.querySelector('[data-ref-empty]'); + if (empty && groups.length) { empty.hidden = total > 0; } refSelect(sw, 0); } - function refSelect(sw, index) { - var panel = refPanelOf(sw); + function refSelect(sw, index, keep) { var input = sw.querySelector('[data-ref-filter]'); - var shown = refShown(panel); + var shown = refShown(sw); if (!shown.length) { input.removeAttribute('aria-activedescendant'); return; } index = Math.max(0, Math.min(shown.length - 1, index)); shown.forEach(function (li, i) { li.setAttribute('aria-selected', i === index ? 'true' : 'false'); }); input.setAttribute('aria-activedescendant', shown[index].id); - shown[index].scrollIntoView({ block: 'nearest' }); - panel.__sel = index; + if (!keep) { shown[index].scrollIntoView({ block: 'nearest' }); } + sw.__refSel = index; } // Opening the switcher clears the filter and focuses it. @@ -2113,31 +2124,25 @@ input.focus(); }, true); - document.addEventListener('click', function (e) { - var tab = e.target && e.target.closest ? e.target.closest('[data-ref-tab]') : null; - if (!tab) { return; } - var sw = refSwitchOf(tab); - var kind = tab.getAttribute('data-ref-tab'); - sw.querySelectorAll('[data-ref-tab]').forEach(function (t) { - t.setAttribute('aria-selected', t === tab ? 'true' : 'false'); - }); - sw.querySelectorAll('[data-ref-panel]').forEach(function (p) { - p.hidden = p.getAttribute('data-ref-panel') !== kind; - }); - refApply(sw); + // The pointer moves the selection, so the keys pick up where it is. + document.addEventListener('mouseover', function (e) { + var li = e.target && e.target.closest ? e.target.closest('[data-ref-item]') : null; + if (!li) { return; } + var sw = refSwitchOf(li); + var i = refShown(sw).indexOf(li); + if (i >= 0 && i !== sw.__refSel) { refSelect(sw, i, true); } }, false); document.addEventListener('keydown', function (e) { var input = e.target && e.target.closest ? e.target.closest('[data-ref-filter]') : null; if (!input) { return; } var sw = refSwitchOf(input); - var panel = refPanelOf(sw); - var sel = panel.__sel || 0; + var sel = sw.__refSel || 0; if (e.key === 'ArrowDown') { e.preventDefault(); refSelect(sw, sel + 1); } else if (e.key === 'ArrowUp') { e.preventDefault(); refSelect(sw, sel - 1); } else if (e.key === 'Enter') { e.preventDefault(); - var item = refShown(panel)[sel]; + var item = refShown(sw)[sel]; var link = item ? item.querySelector('a') : null; if (link) { sw.open = false; link.click(); } } diff --git a/crates/forge-web/src/pages/refs.rs b/crates/forge-web/src/pages/refs.rs index 611a18f..89e1d73 100644 --- a/crates/forge-web/src/pages/refs.rs +++ b/crates/forge-web/src/pages/refs.rs @@ -53,6 +53,7 @@ pub fn ref_links( name: r.name.clone(), href: repo_href(&repo.owner_name, &repo.name, "tree", &r.name), current: r.name == current, + default: r.kind == RefKind::Branch && r.name == default_branch, updated: r.committer_time, }; let branches = sorted diff --git a/crates/forge-web/src/views/mod.rs b/crates/forge-web/src/views/mod.rs index c7970ce..5d98223 100644 --- a/crates/forge-web/src/views/mod.rs +++ b/crates/forge-web/src/views/mod.rs @@ -23,7 +23,7 @@ use topcoat::context::{Cx, try_app_context}; use topcoat::router::request::uri; use topcoat::router::response::{Response, response_headers}; use topcoat::router::{Body, Next, layer}; -use topcoat::view::{Child, View, component, view}; +use topcoat::view::{Child, Unescaped, View, component, view}; use crate::i18n::admin::{self as ad, K as AK}; use crate::i18n::code::{self as g, K}; @@ -1222,61 +1222,69 @@ pub async fn repo_tabs( } /// A branch or tag in the ref switcher. `href` points at its root tree; `updated` is the commit -/// time of its tip (unix seconds). +/// time of its tip (unix seconds); `default` marks the repository's default branch. #[derive(Clone)] pub struct RefLink { pub name: String, pub href: String, pub current: bool, + pub default: bool, pub updated: i64, } -/// Entries listed before the filter narrows the list. The rest stay in the page, hidden, so the -/// filter still finds every name. -pub const REF_SHOWN: usize = 10; +/// Entries each section lists before the filter narrows it. The rest stay in the page, hidden, so +/// the filter still finds every name. +pub const REF_SHOWN: usize = 8; -/// One tab of the ref switcher: its entries, then the link to the full list. +const BRANCH_ICON: &str = r#""#; +const TAG_ICON: &str = r#""#; + +/// One section of the ref switcher: a heading with its count, then its entries. An empty section +/// is left out. #[component] -async fn ref_panel( +async fn ref_group( lang: Lang, kind: &'static str, + heading: &'static str, links: Vec, - all_href: String, - all_label: &'static str, + now: i64, ) -> Result { - let empty = links.is_empty(); + let count = links.len(); + let icon = if kind == "tags" { TAG_ICON } else { BRANCH_ICON }; + let head_id = format!("ref-head-{kind}"); Ok(view! { - + } }) } /// Branch and tag switcher for the browse bar: a button showing the current ref that opens a -/// popover with a filter, Branches and Tags tabs, and a link to each full list. The filter, tabs and -/// arrow keys are wired in `assets/nav.js`; without it the popover still lists the first entries. +/// command-palette popover: a search field over one list with a Branches and a Tags section, each +/// row with its last commit's age, and a footer with key hints and links to the full lists. The +/// filter, match highlight and arrow keys are wired in `assets/nav.js`; without it the popover +/// still lists the first entries of each section. #[component] pub async fn ref_selector( lang: Lang, @@ -1289,29 +1297,35 @@ pub async fn ref_selector( ) -> Result { // A tag shows a tag icon only when it is the current ref and no branch of that name is. let is_tag = !branches.iter().any(|b| b.current) && tags.iter().any(|t| t.current); + let none = branches.is_empty() && tags.is_empty(); + let now = now_unix(); Ok(view! {
- if is_tag { - - } else { - - } + (current.as_str())
-
+ +
+ ref_group(lang: lang, kind: "branches", heading: g::t(lang, K::BranchesTitle), links: branches, now: now) + ref_group(lang: lang, kind: "tags", heading: g::t(lang, K::TagsTitle), links: tags, now: now) + +
+ - ref_panel(lang: lang, kind: "branches", links: branches, all_href: branches_href, all_label: g::t(lang, K::ViewAllBranches)) - ref_panel(lang: lang, kind: "tags", links: tags, all_href: tags_href, all_label: g::t(lang, K::ViewAllTags))
}) diff --git a/style/main.scss b/style/main.scss index 3f19630..b0fb771 100644 --- a/style/main.scss +++ b/style/main.scss @@ -1164,148 +1164,229 @@ code { } } -// Branch switcher popover: filter and tabs on top, the entries below, scrolling inside. +// Branch switcher popover, laid out as a command palette: a borderless search row, one scrolling +// list with a Branches and a Tags section, and a footer with key hints and the full lists. .ref-menu { position: absolute; left: 0; top: calc(100% + 6px); z-index: 10; - width: 300px; + width: 360px; max-width: calc(100vw - 32px); - max-height: 60vh; + max-height: min(60vh, 480px); display: flex; flex-direction: column; + overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); - box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); + box-shadow: var(--shadow); + + kbd { + min-width: 18px; + padding: 0 5px; + font-family: var(--mono); + font-size: 11px; + line-height: 18px; + text-align: center; + color: var(--muted); + background: var(--surface); + border: 1px solid var(--border-strong); + border-radius: var(--radius-sm); + } } -// The tabs row is the bottom edge of the top block: its underline sits on the divider. -.ref-top { - padding: 8px 8px 0; +// The search row is part of the menu, not a field inside it: no box, only the divider below. +.ref-search { + flex: none; + display: flex; + align-items: center; + gap: 10px; + padding: 0 12px; + color: var(--muted); border-bottom: 1px solid var(--border); + + &:focus-within { + color: var(--accent); + } } .ref-filter { - width: 100%; - height: var(--control-h); - box-sizing: border-box; - padding: 0 10px; + flex: 1 1 auto; + min-width: 0; + height: 46px; + padding: 0; font: inherit; - font-size: 14px; + font-size: 15px; color: var(--text); - background: var(--surface-2); - border: 1px solid var(--border); - border-radius: var(--radius-md); + background: transparent; + border: 0; + + &::placeholder { + color: var(--muted); + } &:focus, &:focus-visible { outline: none; - border-color: var(--focus); - box-shadow: 0 0 0 3px var(--accent-soft); - } -} - -// Underline tabs: the 2px underline overlaps the 1px divider of .ref-top. -.ref-tabs { - display: flex; - gap: 16px; - margin: 8px 0 -1px; - - button { - flex: 0 0 auto; - min-height: 32px; - padding: 0 2px; - font: inherit; - font-size: 13px; - color: var(--muted); - background: transparent; - border: 0; - border-bottom: 2px solid transparent; - border-radius: 0; - cursor: pointer; - - &:hover { - color: var(--text); - } - - &[aria-selected="true"] { - color: var(--text); - font-weight: 600; - border-bottom-color: var(--accent); - } - - &:focus-visible { - outline: 2px solid var(--focus); - outline-offset: -2px; - box-shadow: none; - } + box-shadow: none; } } -.ref-panel { +.ref-results { min-height: 0; overflow-y: auto; - padding: 4px 0; + padding: 6px; } -.ref-note { - margin: 8px 14px; +.ref-group + .ref-group { + margin-top: 6px; + padding-top: 6px; + border-top: 1px dashed var(--border); } -.ref-all { - display: block; - margin-top: 4px; - padding: 8px 14px; - font-size: 13px; - color: var(--text-2); - text-decoration: none; - border-top: 1px solid var(--border); +.ref-head { + display: flex; + align-items: center; + gap: 6px; + padding: 6px 8px 4px; + font-size: 11px; + font-weight: 600; + letter-spacing: 0.06em; + text-transform: uppercase; + color: var(--muted); +} - &:hover { - color: var(--text); - background: var(--surface-2); - } +.ref-count { + padding: 0 6px; + font-family: var(--mono); + font-size: 10px; + letter-spacing: 0; + line-height: 16px; + background: var(--surface-2); + border-radius: var(--radius-full); +} + +.ref-note { + margin: 10px 8px; } -// Rows: a fixed 16px gutter holds the checkmark on the current ref, so names line up. +// Rows: kind icon, the name in mono, an optional default chip, and the tip's age pushed right. +// The selected row (keys or pointer) gets a soft fill; the current ref an accent rail and name. .ref-list { list-style: none; margin: 0; padding: 0; - li[aria-selected="true"] a, - a:hover { - background: var(--surface-2); - } - a { + position: relative; display: flex; align-items: center; gap: 8px; - padding: 6px 14px; + padding: 7px 8px 7px 10px; color: var(--text); text-decoration: none; + border-radius: var(--radius-md); + } - &.current { + li[aria-selected="true"] a { + background: var(--surface-2); + } + + li[aria-current="true"] a { + color: var(--accent); + background: var(--accent-soft); + + &::before { + content: ""; + position: absolute; + left: 0; + top: 7px; + bottom: 7px; + width: 3px; + background: var(--accent); + border-radius: var(--radius-full); + } + + .ref-text { font-weight: 600; } + + .ref-kind { + color: inherit; + } } - .ref-check { + .ref-kind { display: inline-flex; flex: none; - width: 16px; - height: 16px; + color: var(--muted); + + svg { + width: 14px; + height: 14px; + } } .ref-text { min-width: 0; + font-family: var(--mono); + font-size: 13px; word-break: break-all; + + mark { + color: inherit; + background: var(--row-target); + border-radius: 2px; + } + } + + .ref-chip { + flex: none; + padding: 0 6px; + font-size: 11px; + line-height: 18px; + color: var(--text-2); + border: 1px solid var(--border-strong); + border-radius: var(--radius-full); + } + + .ref-age { + flex: none; + margin-left: auto; + padding-left: 8px; + font-size: 12px; + color: var(--muted); + white-space: nowrap; + } +} + +.ref-foot { + flex: none; + display: flex; + align-items: center; + gap: 14px; + padding: 8px 12px; + font-size: 12px; + background: var(--surface-2); + border-top: 1px solid var(--border); + + a { + color: var(--text-2); + text-decoration: none; + + &:hover { + color: var(--accent); + } } } +.ref-keys { + display: inline-flex; + gap: 4px; + margin-right: auto; +} + .crumbs { min-width: 0; font-size: 0.9375rem; @@ -2040,29 +2121,23 @@ code { box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.12), 0 0 0 100vmax rgba(0, 0, 0, 0.4); } - .ref-top { - padding: 8px 16px 0; - } - - .ref-note { - margin: 8px 16px; - } - .ref-filter { - height: 44px; + height: 52px; font-size: 16px; } - .ref-tabs button { - min-height: 44px; + .ref-list a { + padding: 12px 10px 12px 12px; } - .ref-list a { - padding: 12px 16px; + // No keyboard on a phone: the footer keeps only the links. + .ref-keys { + display: none; } - .ref-all { - padding: 14px 16px; + .ref-foot { + justify-content: flex-end; + padding: 12px 16px; } }