Skip to content

Commit 48c4a7e

Browse files
wxiaoguangdelvh
andauthored
Rewrite the DiffFileTreeItem and fix misalignment (#26565)
Fix some layout / user-interaction problems and close #25650 , the code has been simplified (+46 −108) <details> ![image](https://github.com/go-gitea/gitea/assets/2114189/55c38812-3338-4048-9137-0cae0ef213e8) </details> --------- Co-authored-by: delvh <[email protected]>
1 parent 30e5278 commit 48c4a7e

File tree

2 files changed

+46
-108
lines changed

2 files changed

+46
-108
lines changed

web_src/js/components/DiffFileTree.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<template>
22
<div v-if="store.fileTreeIsVisible" class="gt-mr-3 gt-mt-3 diff-detail-box">
33
<!-- only render the tree if we're visible. in many cases this is something that doesn't change very often -->
4-
<div class="ui list">
5-
<DiffFileTreeItem v-for="item in fileTree" :key="item.name" :item="item"/>
6-
</div>
4+
<DiffFileTreeItem v-for="item in fileTree" :key="item.name" :item="item"/>
75
<div v-if="store.isIncomplete" class="gt-pt-2">
86
<a :class="['ui', 'basic', 'tiny', 'button', store.isLoadingNewData ? 'disabled' : '']" @click.stop="loadMoreData">{{ store.showMoreMessage }}</a>
97
</div>
Lines changed: 45 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,24 @@
11
<template>
2-
<div v-show="show" :title="item.name">
3-
<!--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"-->
4-
<div class="item" :class="[item.isFile ? 'filewrapper gt-p-1 gt-ac' : '', store.selectedItem === '#diff-' + item.file?.NameHash ? 'selected' : '']">
5-
<!-- Files -->
6-
<SvgIcon
7-
v-if="item.isFile"
8-
name="octicon-file"
9-
class="svg-icon file"
10-
/>
11-
<a
12-
v-if="item.isFile"
13-
:class="['file gt-ellipsis', {'viewed': item.file.IsViewed}]"
14-
:href="item.isFile ? '#diff-' + item.file.NameHash : ''"
15-
>{{ item.name }}</a>
16-
<SvgIcon
17-
v-if="item.isFile"
18-
:name="getIconForDiffType(item.file.Type)"
19-
:class="['svg-icon', getIconForDiffType(item.file.Type), 'status']"
20-
/>
2+
<!--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"-->
3+
<a
4+
v-if="item.isFile" class="item-file"
5+
:class="{'selected': store.selectedItem === '#diff-' + item.file.NameHash, 'viewed': item.file.IsViewed}"
6+
:title="item.name" :href="'#diff-' + item.file.NameHash"
7+
>
8+
<!-- file -->
9+
<SvgIcon name="octicon-file"/>
10+
<span class="gt-ellipsis gt-f1">{{ item.name }}</span>
11+
<SvgIcon :name="getIconForDiffType(item.file.Type).name" :class="getIconForDiffType(item.file.Type).classes"/>
12+
</a>
13+
<div v-else class="item-directory" :title="item.name" @click.stop="collapsed = !collapsed">
14+
<!-- directory -->
15+
<SvgIcon :name="collapsed ? 'octicon-chevron-right' : 'octicon-chevron-down'"/>
16+
<SvgIcon class="text primary" name="octicon-file-directory-fill"/>
17+
<span class="gt-ellipsis">{{ item.name }}</span>
18+
</div>
2119

22-
<!-- Directories -->
23-
<div v-if="!item.isFile" class="directory gt-p-1 gt-ac" @click.stop="handleClick(item.isFile)">
24-
<SvgIcon
25-
class="svg-icon"
26-
:name="collapsed ? 'octicon-chevron-right' : 'octicon-chevron-down'"
27-
/>
28-
<SvgIcon
29-
class="svg-icon directory"
30-
name="octicon-file-directory-fill"
31-
/>
32-
<span class="gt-ellipsis">{{ item.name }}</span>
33-
</div>
34-
<div v-show="!collapsed">
35-
<DiffFileTreeItem v-for="childItem in item.children" :key="childItem.name" :item="childItem" class="list"/>
36-
</div>
37-
</div>
20+
<div v-if="item.children?.length" v-show="!collapsed" class="sub-items">
21+
<DiffFileTreeItem v-for="childItem in item.children" :key="childItem.name" :item="childItem"/>
3822
</div>
3923
</template>
4024

@@ -49,30 +33,19 @@ export default {
4933
type: Object,
5034
required: true
5135
},
52-
show: {
53-
type: Boolean,
54-
required: false,
55-
default: true
56-
},
5736
},
5837
data: () => ({
5938
store: diffTreeStore(),
6039
collapsed: false,
6140
}),
6241
methods: {
63-
handleClick(itemIsFile) {
64-
if (itemIsFile) {
65-
return;
66-
}
67-
this.collapsed = !this.collapsed;
68-
},
6942
getIconForDiffType(pType) {
7043
const diffTypes = {
71-
1: 'octicon-diff-added',
72-
2: 'octicon-diff-modified',
73-
3: 'octicon-diff-removed',
74-
4: 'octicon-diff-renamed',
75-
5: 'octicon-diff-modified', // there is no octicon for copied, so modified should be ok
44+
1: {name: 'octicon-diff-added', classes: ['text', 'green']},
45+
2: {name: 'octicon-diff-modified', classes: ['text', 'yellow']},
46+
3: {name: 'octicon-diff-removed', classes: ['text', 'red']},
47+
4: {name: 'octicon-diff-renamed', classes: ['text', 'teal']},
48+
5: {name: 'octicon-diff-renamed', classes: ['text', 'green']}, // there is no octicon for copied, so renamed should be ok
7649
};
7750
return diffTypes[pType];
7851
},
@@ -81,75 +54,42 @@ export default {
8154
</script>
8255

8356
<style scoped>
84-
.svg-icon.status {
85-
float: right;
86-
}
87-
88-
.svg-icon.file {
89-
color: var(--color-secondary-dark-7);
90-
}
91-
92-
.svg-icon.directory {
93-
color: var(--color-primary);
94-
}
95-
96-
.svg-icon.octicon-diff-modified {
97-
color: var(--color-yellow);
98-
}
99-
100-
.svg-icon.octicon-diff-added {
101-
color: var(--color-green);
102-
}
103-
104-
.svg-icon.octicon-diff-removed {
105-
color: var(--color-red);
57+
a, a:hover {
58+
text-decoration: none;
59+
color: var(--color-text);
10660
}
10761
108-
.svg-icon.octicon-diff-renamed {
109-
color: var(--color-teal);
62+
.sub-items {
63+
padding-left: 9px;
11064
}
11165
112-
.item.filewrapper {
113-
display: grid !important;
114-
grid-template-columns: 20px 7fr 1fr;
115-
padding-left: 18px !important;
66+
.item-file {
67+
margin-left: 20px;
11668
}
11769
118-
.item.filewrapper:hover, div.directory:hover {
119-
color: var(--color-text);
120-
background: var(--color-hover);
121-
border-radius: 4px;
122-
}
123-
124-
.item.filewrapper.selected {
70+
.item-file.selected {
12571
color: var(--color-text);
12672
background: var(--color-active);
12773
border-radius: 4px;
12874
}
12975
130-
div.directory {
131-
display: grid;
132-
grid-template-columns: 18px 20px auto;
133-
user-select: none;
134-
cursor: pointer;
135-
}
136-
137-
div.list {
138-
padding-bottom: 0 !important;
139-
padding-top: inherit !important;
76+
.item-file.viewed {
77+
color: var(--color-text-light-3);
14078
}
14179
142-
a {
143-
text-decoration: none;
144-
color: var(--color-text);
80+
.item-file,
81+
.item-directory {
82+
display: flex;
83+
align-items: center;
84+
gap: 0.25em;
85+
padding: 2px;
14586
}
14687
147-
a:hover {
148-
text-decoration: none;
88+
.item-file:hover,
89+
.item-directory:hover {
14990
color: var(--color-text);
150-
}
151-
152-
a.file.viewed {
153-
color: var(--color-text-light-3);
91+
background: var(--color-hover);
92+
border-radius: 4px;
93+
cursor: pointer;
15494
}
15595
</style>

0 commit comments

Comments
 (0)