Skip to content

Commit ee2f52a

Browse files
committed
use a for file tree files
1 parent 3c6e803 commit ee2f52a

File tree

2 files changed

+40
-41
lines changed

2 files changed

+40
-41
lines changed

web_src/js/components/ViewFileTree.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ async function loadViewContent(url: string) {
3737
document.querySelector('.repo-view-content').innerHTML = await response.text();
3838
}
3939
40-
async function navigateTreeView(treePath: string, newTab?: boolean) {
41-
const url = `${props.repoLink}/src/${props.currentRefNameSubURL}/${pathEscapeSegments(treePath)}`;
42-
if (newTab) {
43-
window.open(url, '_blank');
44-
return;
45-
}
40+
async function navigateTreeView(treePath: string) {
41+
const url = getWebUrl(treePath);
4642
window.history.pushState({treePath, url}, null, url);
4743
selectedItem.value = treePath;
4844
await loadViewContent(url);
4945
}
5046
47+
function getWebUrl(treePath: string) {
48+
return `${props.repoLink}/src/${props.currentRefNameSubURL}/${pathEscapeSegments(treePath)}`;
49+
}
50+
5151
onMounted(async () => {
5252
selectedItem.value = props.treePath;
5353
files.value = await loadChildren('', props.treePath);
@@ -62,7 +62,7 @@ onMounted(async () => {
6262
<template>
6363
<div class="view-file-tree-items" ref="elRoot">
6464
<!-- only render the tree if we're visible. in many cases this is something that doesn't change very often -->
65-
<ViewFileTreeItem v-for="item in files" :key="item.name" :item="item" :selected-item="selectedItem" :navigate-view-content="navigateTreeView" :load-children="loadChildren"/>
65+
<ViewFileTreeItem v-for="item in files" :key="item.name" :item="item" :selected-item="selectedItem" :get-web-url="getWebUrl" :navigate-view-content="navigateTreeView" :load-children="loadChildren"/>
6666
</div>
6767
</template>
6868

web_src/js/components/ViewFileTreeItem.vue

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@ type Item = {
1414
1515
const props = defineProps<{
1616
item: Item,
17-
navigateViewContent:(treePath: string, newTab?: boolean) => void,
17+
navigateViewContent:(treePath: string) => void,
1818
loadChildren:(treePath: string, subPath?: string) => Promise<Item[]>,
19+
getWebUrl:(treePath: string) => string,
1920
selectedItem?: string,
2021
}>();
2122
2223
const isLoading = ref(false);
2324
const children = ref(props.item.children);
2425
const collapsed = ref(!props.item.children);
2526
26-
const doLoadChildren = async () => {
27+
const doLoadChildren = async (e?: MouseEvent) => {
28+
// the event is only not undefined if the user explicitly clicked on the directory item toggle. the preventDefault
29+
// stops the event from bubbling up and causing a directory content load
30+
e?.preventDefault();
31+
2732
collapsed.value = !collapsed.value;
2833
if (!collapsed.value && props.loadChildren) {
2934
isLoading.value = true;
@@ -35,79 +40,71 @@ const doLoadChildren = async () => {
3540
}
3641
};
3742
38-
const doLoadDirContent = (event: MouseEvent) => {
39-
// open the directory in a new tab if either
40-
// - the auxiliary button (usually the mouse wheel button) is the origin of the click
41-
// - the ctrl key or meta key (for mac support) was pressed while clicking
42-
const openNewTab = event.button === 1 || event.ctrlKey || event.metaKey;
43-
if (!openNewTab) doLoadChildren();
44-
props.navigateViewContent(props.item.fullPath, openNewTab);
45-
};
43+
const doLoadDirContent = (e: MouseEvent) => {
44+
// only load the directory content without a window refresh if the user didn't press any special key
45+
if (e.button !== 0 || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey) return;
46+
e.preventDefault();
4647
47-
const doLoadFileContent = (event: MouseEvent) => {
48-
const openNewTab = event.button === 1 || event.ctrlKey || event.metaKey;
49-
props.navigateViewContent(props.item.fullPath, openNewTab);
48+
doLoadChildren();
49+
props.navigateViewContent(props.item.fullPath);
5050
};
5151
52-
const doGotoSubModule = (event: MouseEvent) => {
53-
const openNewTab = event.button === 1 || event.ctrlKey || event.metaKey;
54-
if (openNewTab) {
55-
window.open(props.item.submoduleUrl, '_blank');
56-
return;
57-
}
58-
location.href = props.item.submoduleUrl;
52+
const doLoadFileContent = (e: MouseEvent) => {
53+
if (e.button !== 0 || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey) return;
54+
e.preventDefault();
55+
56+
props.navigateViewContent(props.item.fullPath);
5957
};
6058
</script>
6159

6260
<!--title instead of tooltip above as the tooltip needs too much work with the current methods, i.e. not being loaded or staying open for "too long"-->
6361
<template>
64-
<div
62+
<a
6563
v-if="item.entryMode === 'commit'" class="tree-item type-submodule"
6664
:title="item.entryName"
67-
@click.stop="doGotoSubModule"
68-
@click.middle.stop="doGotoSubModule"
65+
:href="getWebUrl(item.fullPath)"
6966
>
7067
<!-- submodule -->
7168
<div class="item-content">
7269
<!-- eslint-disable-next-line vue/no-v-html -->
7370
<span class="tw-contents" v-html="item.entryIcon"/>
7471
<span class="gt-ellipsis tw-flex-1">{{ item.entryName }}</span>
7572
</div>
76-
</div>
77-
<div
73+
</a>
74+
<a
7875
v-else-if="item.entryMode === 'symlink'" class="tree-item type-symlink"
7976
:class="{'selected': selectedItem === item.fullPath}"
8077
:title="item.entryName"
78+
:href="getWebUrl(item.fullPath)"
8179
@click.stop="doLoadFileContent"
82-
@click.middle.stop="doLoadFileContent"
8380
>
8481
<!-- symlink -->
8582
<div class="item-content">
8683
<!-- eslint-disable-next-line vue/no-v-html -->
8784
<span class="tw-contents" v-html="item.entryIcon"/>
8885
<span class="gt-ellipsis tw-flex-1">{{ item.entryName }}</span>
8986
</div>
90-
</div>
91-
<div
87+
</a>
88+
<a
9289
v-else-if="item.entryMode !== 'tree'" class="tree-item type-file"
9390
:class="{'selected': selectedItem === item.fullPath}"
9491
:title="item.entryName"
92+
:href="getWebUrl(item.fullPath)"
9593
@click.stop="doLoadFileContent"
96-
@click.middle.stop="doLoadFileContent"
9794
>
9895
<!-- file -->
9996
<div class="item-content">
10097
<!-- eslint-disable-next-line vue/no-v-html -->
10198
<span class="tw-contents" v-html="item.entryIcon"/>
10299
<span class="gt-ellipsis tw-flex-1">{{ item.entryName }}</span>
103100
</div>
104-
</div>
105-
<div
101+
</a>
102+
<a
106103
v-else class="tree-item type-directory"
107104
:class="{'selected': selectedItem === item.fullPath}"
108105
:title="item.entryName"
106+
:href="getWebUrl(item.fullPath)"
109107
@click.stop="doLoadDirContent"
110-
@click.middle.stop="doLoadDirContent"
111108
>
112109
<!-- directory -->
113110
<div class="item-toggle">
@@ -119,10 +116,10 @@ const doGotoSubModule = (event: MouseEvent) => {
119116
<span class="tw-contents" v-html="(!collapsed && item.entryIconOpen) ? item.entryIconOpen : item.entryIcon"/>
120117
<span class="gt-ellipsis">{{ item.entryName }}</span>
121118
</div>
122-
</div>
119+
</a>
123120

124121
<div v-if="children?.length" v-show="!collapsed" class="sub-items">
125-
<ViewFileTreeItem v-for="childItem in children" :key="childItem.entryName" :item="childItem" :selected-item="selectedItem" :navigate-view-content="navigateViewContent" :load-children="loadChildren"/>
122+
<ViewFileTreeItem v-for="childItem in children" :key="childItem.entryName" :item="childItem" :selected-item="selectedItem" :get-web-url="getWebUrl" :navigate-view-content="navigateViewContent" :load-children="loadChildren"/>
126123
</div>
127124
</template>
128125
<style scoped>
@@ -145,6 +142,8 @@ const doGotoSubModule = (event: MouseEvent) => {
145142
}
146143
147144
.tree-item {
145+
color: inherit;
146+
text-decoration: inherit;
148147
display: grid;
149148
grid-template-columns: 16px 1fr;
150149
grid-template-areas: "toggle content";

0 commit comments

Comments
 (0)