0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-11-10 04:55:22 +01:00

update title when changing file via file tree

This commit is contained in:
bytedream 2025-10-27 16:37:32 +01:00
parent 5f757af622
commit 754535318c
4 changed files with 13 additions and 1 deletions

View File

@ -10,6 +10,7 @@
{{/* TODO: Dynamically move components such as refSelector and createPR here */}} {{/* TODO: Dynamically move components such as refSelector and createPR here */}}
<div id="view-file-tree" class="tw-overflow-auto tw-h-full is-loading" <div id="view-file-tree" class="tw-overflow-auto tw-h-full is-loading"
data-repo-link="{{.RepoLink}}" data-repo-link="{{.RepoLink}}"
data-repo-name="{{.Repository.Name}}"
data-tree-path="{{$.TreePath}}" data-tree-path="{{$.TreePath}}"
data-current-ref-name-sub-url="{{.RefTypeNameSubURL}}" data-current-ref-name-sub-url="{{.RefTypeNameSubURL}}"
></div> ></div>

View File

@ -7,6 +7,7 @@ const elRoot = useTemplateRef('elRoot');
const props = defineProps({ const props = defineProps({
repoLink: {type: String, required: true}, repoLink: {type: String, required: true},
repoName: {type: String, required: true},
treePath: {type: String, required: true}, treePath: {type: String, required: true},
currentRefNameSubURL: {type: String, required: true}, currentRefNameSubURL: {type: String, required: true},
}); });

View File

@ -4,7 +4,7 @@ import {pathEscapeSegments} from '../utils/url.ts';
import {createElementFromHTML} from '../utils/dom.ts'; import {createElementFromHTML} from '../utils/dom.ts';
import {html} from '../utils/html.ts'; import {html} from '../utils/html.ts';
export function createViewFileTreeStore(props: {repoLink: string, treePath: string, currentRefNameSubURL: string}) { export function createViewFileTreeStore(props: {repoLink: string, repoName: string, treePath: string, currentRefNameSubURL: string}) {
const store = reactive({ const store = reactive({
rootFiles: [], rootFiles: [],
selectedItem: props.treePath, selectedItem: props.treePath,
@ -32,14 +32,23 @@ export function createViewFileTreeStore(props: {repoLink: string, treePath: stri
async navigateTreeView(treePath: string) { async navigateTreeView(treePath: string) {
const url = store.buildTreePathWebUrl(treePath); const url = store.buildTreePathWebUrl(treePath);
const title = store.buildTitle(store.selectedItem, treePath);
window.history.pushState({treePath, url}, null, url); window.history.pushState({treePath, url}, null, url);
store.selectedItem = treePath; store.selectedItem = treePath;
await store.loadViewContent(url); await store.loadViewContent(url);
document.title = title;
}, },
buildTreePathWebUrl(treePath: string) { buildTreePathWebUrl(treePath: string) {
return `${props.repoLink}/src/${props.currentRefNameSubURL}/${pathEscapeSegments(treePath)}`; return `${props.repoLink}/src/${props.currentRefNameSubURL}/${pathEscapeSegments(treePath)}`;
}, },
buildTitle(oldTreePath: string, treePath: string) {
// the title always starts with "<repoName>/<treePath>"
const oldPrefixLength = props.repoName.length + 1 + oldTreePath.length;
const titleSuffix = document.title.substring(oldPrefixLength);
return `${props.repoName}/${treePath}${titleSuffix}`;
},
}); });
return store; return store;
} }

View File

@ -31,6 +31,7 @@ export async function initRepoViewFileTree() {
const fileTree = sidebar.querySelector('#view-file-tree'); const fileTree = sidebar.querySelector('#view-file-tree');
createApp(ViewFileTree, { createApp(ViewFileTree, {
repoLink: fileTree.getAttribute('data-repo-link'), repoLink: fileTree.getAttribute('data-repo-link'),
repoName: fileTree.getAttribute('data-repo-name'),
treePath: fileTree.getAttribute('data-tree-path'), treePath: fileTree.getAttribute('data-tree-path'),
currentRefNameSubURL: fileTree.getAttribute('data-current-ref-name-sub-url'), currentRefNameSubURL: fileTree.getAttribute('data-current-ref-name-sub-url'),
}).mount(fileTree); }).mount(fileTree);