diff --git a/crates/forge-web/assets/nav.js b/crates/forge-web/assets/nav.js index cd63849..ca87cf1 100644 --- a/crates/forge-web/assets/nav.js +++ b/crates/forge-web/assets/nav.js @@ -361,6 +361,9 @@ // A fit pane keeps its scroll when the page stays put (a live change, a post, a filter), by its place in the page. var paneTops = how === 'live' || how === 'post' || how === 'query' ? paneScrolls() : null; var bars = how === 'live' ? barSegments() : null; + var jump = liveJump && liveJump.path === dest.pathname ? liveJump.input : null; + var jumped = jump ? jump.value : ''; + liveJump = null; var steps = captureSteps(); adopt(doc, keepFields, dd, how === 'live' ? captureJobs() : null); restoreSteps(steps); @@ -375,6 +378,7 @@ else if (how === 'post' || how === 'query') { history.replaceState(null, '', dest.href); } shown = dest.pathname + dest.search; if (how === 'nav' || how === 'pop') { focusMain(); } + if (jump) { landSearch(jumped); } if (how !== 'live' && placeHash(dest.hash)) { return; } if (how === 'live' && placeAnchor(at)) { return; } if (how === 'post' || how === 'query' || how === 'live') { window.scrollTo(x, y); } @@ -1552,6 +1556,15 @@ var q = new URLSearchParams(data).toString(); var dest = withoutHash(url); dest.search = q ? '?' + q : ''; + // Enter in a live field on its own results page runs the search now and leaves the reader typing. + var typing = document.activeElement; + if (typing && typing.form === form && typing.hasAttribute('data-live-search') && url.pathname === location.pathname) { + clearTimeout(searchTimer); + searchTimer = null; + if (dest.pathname + dest.search === shown) { pending.delete(form); return; } + load({ target: dest, dest: dest, init: GET_INIT, how: 'query', keep: true, post: false, form: form }); + return; + } saveScroll(); load({ target: dest, dest: dest, init: GET_INIT, how: 'nav', keep: false, post: false, form: form }); return; @@ -1586,7 +1599,18 @@ // Search as you type: a search field marked data-live-search refetches its GET form 250 ms after // the last keystroke and swaps the page in place, with no history entry and the field's focus and // caret kept. A newer request drops an older answer. The submit button stays as the no-JS path. + // A field whose results are on another page (the repo head's code search) goes there once it has + // text: that page's field takes over with what was typed, so the reader never stops typing. var searchTimer = null; + var liveJump = null; + function landSearch(value) { + var el = document.querySelector('[data-live-search]'); + if (!el) { return; } + el.value = value; + el.focus({ preventScroll: true }); + el.setSelectionRange(value.length, value.length); + if (value !== el.defaultValue) { el.dispatchEvent(new Event('input', { bubbles: true })); } + } function liveSearch(input) { var el = input.isConnected ? input : document.querySelector('[data-live-search]'); var form = el && el.form; @@ -1596,6 +1620,13 @@ var q = new URLSearchParams(new FormData(form)).toString(); dest.search = q ? '?' + q : ''; if (dest.pathname + dest.search === shown) { return; } + if (dest.pathname !== location.pathname) { + if (!el.value.trim()) { return; } + liveJump = { path: dest.pathname, input: el }; + saveScroll(); + load({ target: dest, dest: dest, init: GET_INIT, how: 'nav', keep: false, post: false, form: null }); + return; + } load({ target: dest, dest: dest, init: GET_INIT, how: 'query', keep: true, post: false, form: null }); } document.addEventListener('input', function (e) { diff --git a/crates/forge-web/src/pages/audit_log.rs b/crates/forge-web/src/pages/audit_log.rs index aee800a..e7f6814 100644 --- a/crates/forge-web/src/pages/audit_log.rs +++ b/crates/forge-web/src/pages/audit_log.rs @@ -139,8 +139,8 @@ async fn admin_audit_view(