From d5bbee57d4bb815812a7af6d2c460c9d41d7294d Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sun, 29 Mar 2026 23:17:54 +0200 Subject: [PATCH] fix(web): preserve view mode and path when switching refs the ref selector now navigates to the same view (tree/blob/commits) and path on the new ref, instead of always resetting to tree root Co-Authored-By: Claude Opus 4.6 (1M context) --- webui2/src/routes/$repo/_code.tsx | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/webui2/src/routes/$repo/_code.tsx b/webui2/src/routes/$repo/_code.tsx index 9a07d1f9014153e7f30c79141c82b522775cff65..e11826b182fea902fe68c3fbca31ee0c32a74fa5 100644 --- a/webui2/src/routes/$repo/_code.tsx +++ b/webui2/src/routes/$repo/_code.tsx @@ -39,6 +39,11 @@ function CodeLayout() { const currentPath = allParams._splat ?? ""; const matchRoute = useMatchRoute(); + const isBlobView = !!matchRoute({ + to: "/$repo/blob/$ref/$", + params: { repo, ref: currentRef, _splat: currentPath }, + fuzzy: true, + }); const isCommitsView = !!matchRoute({ to: "/$repo/commits/$ref", params: { repo, ref: currentRef }, @@ -47,11 +52,23 @@ function CodeLayout() { const navigate = useNavigate(); - function handleRefSelect(ref: GitRef) { - void navigate({ - to: "/$repo/tree/$ref/$", - params: { repo, ref: ref.shortName, _splat: "" }, - }); + function handleRefSelect(newRef: GitRef) { + if (isCommitsView) { + void navigate({ + to: "/$repo/commits/$ref", + params: { repo, ref: newRef.shortName }, + }); + } else if (isBlobView) { + void navigate({ + to: "/$repo/blob/$ref/$", + params: { repo, ref: newRef.shortName, _splat: currentPath }, + }); + } else { + void navigate({ + to: "/$repo/tree/$ref/$", + params: { repo, ref: newRef.shortName, _splat: currentPath }, + }); + } } return (