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 (