Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diff improvements #23553

Merged
merged 29 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
628ac21
Diff improvements
silverwind Mar 17, 2023
8a3a364
Left-align inline comment boxes and match to fit markup content
silverwind Mar 19, 2023
6f295f1
merge :target CSS rules
silverwind Mar 19, 2023
7325224
use toggleElem
silverwind Mar 19, 2023
89075fc
restore TODO
silverwind Mar 19, 2023
653bd69
fix height bug of tree
silverwind Mar 19, 2023
1cd28f8
guard against non-existant localStorage
silverwind Mar 19, 2023
b6be634
incorporate .diff-stats changes from #23585
silverwind Mar 20, 2023
b9e8595
move explicit height to .diff-detail-actions
silverwind Mar 20, 2023
9bb2227
Merge branch 'main' into diff-improve
silverwind Mar 20, 2023
6c8c235
re-order to original order
silverwind Mar 20, 2023
13345e1
use flex instead of width, use button instead of a
silverwind Mar 21, 2023
d0d63f1
Add tooltip to toggle button
silverwind Mar 21, 2023
f9df311
don't update tooltip on component mount
silverwind Mar 21, 2023
5a8639b
use longer var names, move button color style
silverwind Mar 21, 2023
204424a
Merge branch 'main' into diff-improve
silverwind Mar 21, 2023
2901e6e
restore max-width
silverwind Mar 21, 2023
cdc0ce8
use css var
silverwind Mar 21, 2023
dd3b846
Merge branch 'main' into diff-improve
silverwind Mar 25, 2023
8a18888
fix tooltip
silverwind Mar 25, 2023
1c6102c
remove line
silverwind Mar 25, 2023
cf1e729
fix colors
silverwind Mar 25, 2023
ea28fc2
fix svg vertical align
silverwind Mar 25, 2023
7a6e133
remove unnecessary updateState on mounted
silverwind Mar 25, 2023
a77615e
remove a color
silverwind Mar 25, 2023
cddccc6
remove obsolete tooltip class
silverwind Mar 27, 2023
36a6926
refactor for grepability
silverwind Mar 27, 2023
6c1d2fc
Merge branch 'main' into diff-improve
silverwind Mar 27, 2023
b4fc7e6
Merge branch 'main' into diff-improve
lunny Mar 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2280,6 +2280,8 @@ diff.image.side_by_side = Side by Side
diff.image.swipe = Swipe
diff.image.overlay = Overlay
diff.has_escaped = This line has hidden Unicode characters
diff.show_file_tree = Show file tree
diff.hide_file_tree = Hide file tree

releases.desc = Track project versions and downloads.
release.releases = Releases
Expand Down
18 changes: 14 additions & 4 deletions templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@
<div>
<div class="diff-detail-box diff-box sticky gt-df gt-sb gt-ac gt-fw">
<div class="gt-df gt-ac gt-fw">
<a class="diff-toggle-file-tree-button muted gt-df gt-ac">
<button class="diff-toggle-file-tree-button gt-df gt-ac" data-show-text="{{.locale.Tr "repo.diff.show_file_tree"}}" data-hide-text="{{.locale.Tr "repo.diff.hide_file_tree"}}">
{{/* the icon meaning is reversed here, "octicon-sidebar-collapse" means show the file tree */}}
{{svg "octicon-sidebar-collapse" 20 "icon hide"}}
{{svg "octicon-sidebar-expand" 20 "icon"}}
</a>
{{svg "octicon-sidebar-collapse" 20 "icon gt-hidden"}}
{{svg "octicon-sidebar-expand" 20 "icon gt-hidden"}}
</button>
<script>
const diffTreeVisible = localStorage?.getItem('diff_file_tree_visible') === 'true';
const diffTreeBtn = document.querySelector('.diff-toggle-file-tree-button');
const diffTreeIcon = `.octicon-sidebar-${diffTreeVisible ? 'expand' : 'collapse'}`;
diffTreeBtn.querySelector(diffTreeIcon).classList.remove('gt-hidden');
diffTreeBtn.setAttribute('data-tooltip-content', diffTreeBtn.getAttribute(diffTreeVisible ? 'data-hide-text' : 'data-show-text'));
</script>
<div class="diff-detail-stats gt-df gt-ac gt-ml-3">
{{svg "octicon-diff" 16 "gt-mr-2"}}{{.locale.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}}
</div>
Expand Down Expand Up @@ -68,6 +75,9 @@
<div id="diff-file-list"></div>
<div id="diff-container">
<div id="diff-file-tree" class="gt-hidden"></div>
<script>
if (diffTreeVisible) document.getElementById('diff-file-tree').classList.remove('gt-hidden');
</script>
<div id="diff-file-boxes" class="sixteen wide column">
{{range $i, $file := .Diff.Files}}
{{/*notice: the index of Diff.Files should not be used for element ID, because the index will be restarted from 0 when doing load-more for PRs with a lot of files*/}}
Expand Down
4 changes: 4 additions & 0 deletions web_src/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ table {
border-collapse: collapse;
}

button {
cursor: pointer;
}

details summary {
cursor: pointer;
}
Expand Down
43 changes: 37 additions & 6 deletions web_src/css/repository.css
Original file line number Diff line number Diff line change
Expand Up @@ -1616,14 +1616,12 @@
padding: 7px 0;
background: var(--color-body);
line-height: 30px;
height: 47px; /* match .ui.attached.header.diff-file-header.sticky-2nd-row */
}

@media (max-width: 991px) {
.repository .diff-detail-box {
flex-direction: column;
align-items: flex-start;
height: 77px; /* match .ui.attached.header.diff-file-header.sticky-2nd-row */
}
}

Expand Down Expand Up @@ -1679,6 +1677,13 @@
}
}

.diff-detail-actions {
/* prevent font-size from increasing element height so that .diff-detail-box comes
out with height of 47px (one line) and 77px (two lines), which is important for
position: sticky */
height: 33px;
}

.repository .diff-detail-box .diff-detail-actions > * {
margin-right: 0;
}
Expand Down Expand Up @@ -1853,10 +1858,24 @@
padding-bottom: 5px;
}

.diff-file-box {
border: 1px solid transparent;
border-radius: var(--border-radius);
}

silverwind marked this conversation as resolved.
Show resolved Hide resolved
/* TODO: this can potentially be made "global" by removing the class prefix */
.diff-file-box .ui.attached.header,
.diff-file-box .ui.attached.table {
margin: 0; /* remove fomantic negative margins */;
width: initial; /* remove fomantic over 100% width */;
max-width: initial; /* remove fomantic over 100% width */;
silverwind marked this conversation as resolved.
Show resolved Hide resolved
}
silverwind marked this conversation as resolved.
Show resolved Hide resolved

.repository .diff-stats {
clear: both;
margin-bottom: 5px;
max-height: 400px;
max-height: 200px;
height: fit-content;
overflow: auto;
padding-left: 0;
}
Expand Down Expand Up @@ -2652,7 +2671,8 @@
filter: drop-shadow(-3px 0 0 var(--color-primary-alpha-30)) !important;
}

.code-comment:target {
.code-comment:target,
.diff-file-box:target {
border-color: var(--color-primary) !important;
border-radius: var(--border-radius) !important;
box-shadow: 0 0 0 3px var(--color-primary-alpha-30) !important;
Expand Down Expand Up @@ -3226,17 +3246,28 @@ td.blob-excerpt {
}

#diff-file-tree {
width: 20%;
flex: 0 0 20%;
max-width: 380px;
line-height: inherit;
position: sticky;
padding-top: 0;
top: 47px;
max-height: calc(100vh - 50px);
max-height: calc(100vh - 47px);
height: 100%;
overflow-y: auto;
}

.diff-toggle-file-tree-button {
background: none;
border: none;
user-select: none;
color: inherit;
}

.diff-toggle-file-tree-button:hover {
color: var(--color-primary);
}

@media (max-width: 991px) {
#diff-file-tree {
display: none !important;
Expand Down
11 changes: 1 addition & 10 deletions web_src/css/review.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
.comment-code-cloud {
padding: 0.5rem 1rem !important;
position: relative;
margin: 0 auto;
max-width: 1000px;
max-width: 820px;
}

@media (max-width: 767px) {
Expand Down Expand Up @@ -308,11 +307,3 @@ a.blob-excerpt:hover {
width: 72px;
height: 10px;
}

.diff-file-box {
border-radius: 0.285rem; /* Just like ui.top.attached.header */
}

.diff-file-box:target {
box-shadow: 0 0 0 3px var(--color-accent);
}
21 changes: 11 additions & 10 deletions web_src/js/components/DiffFileTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<script>
import DiffFileTreeItem from './DiffFileTreeItem.vue';
import {doLoadMoreFiles} from '../features/repo-diff.js';
import {toggleElem} from '../utils/dom.js';

const {pageData} = window.config;
const LOCAL_STORAGE_KEY = 'diff_file_tree_visible';
Expand Down Expand Up @@ -92,8 +93,6 @@ export default {
}
},
mounted() {
// ensure correct buttons when we are mounted to the dom
this.adjustToggleButton(this.fileTreeIsVisible);
// replace the pageData.diffFileInfo.files with our watched data so we get updates
pageData.diffFileInfo.files = this.files;

Expand All @@ -109,15 +108,17 @@ export default {
updateVisibility(visible) {
this.fileTreeIsVisible = visible;
localStorage.setItem(LOCAL_STORAGE_KEY, this.fileTreeIsVisible);
this.adjustToggleButton(this.fileTreeIsVisible);
this.updateState(this.fileTreeIsVisible);
},
adjustToggleButton(visible) {
const [toShow, toHide] = document.querySelectorAll('.diff-toggle-file-tree-button .icon');
toShow.classList.toggle('gt-hidden', visible); // hide the toShow icon if the tree is visible
toHide.classList.toggle('gt-hidden', !visible); // similarly

const diffTree = document.getElementById('diff-file-tree');
diffTree.classList.toggle('gt-hidden', !visible);
updateState(visible) {
const btn = document.querySelector('.diff-toggle-file-tree-button');
const [toShow, toHide] = btn.querySelectorAll('.icon');
const tree = document.getElementById('diff-file-tree');
const newTooltip = btn.getAttribute(visible ? 'data-hide-text' : 'data-show-text');
btn.setAttribute('data-tooltip-content', newTooltip);
toggleElem(tree, visible);
silverwind marked this conversation as resolved.
Show resolved Hide resolved
toggleElem(toShow, !visible);
toggleElem(toHide, visible);
},
loadMoreData() {
this.isLoadingNewData = true;
Expand Down
22 changes: 12 additions & 10 deletions web_src/js/components/DiffFileTreeItem.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div v-show="show" :title="item.name">
<!--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"-->
<div class="item" :class="item.isFile ? 'filewrapper gt-p-1' : ''">
<div class="item" :class="item.isFile ? 'filewrapper gt-p-1 gt-ac' : ''">
silverwind marked this conversation as resolved.
Show resolved Hide resolved
<!-- Files -->
<SvgIcon
v-if="item.isFile"
Expand All @@ -10,7 +10,7 @@
/>
<a
v-if="item.isFile"
class="file gt-ellipsis muted"
class="file gt-ellipsis"
:href="item.isFile ? '#diff-' + item.file.NameHash : ''"
>{{ item.name }}</a>
<SvgIcon
Expand All @@ -20,7 +20,7 @@
/>

<!-- Directories -->
<div v-if="!item.isFile" class="directory gt-p-1" @click.stop="handleClick(item.isFile)">
<div v-if="!item.isFile" class="directory gt-p-1 gt-ac" @click.stop="handleClick(item.isFile)">
silverwind marked this conversation as resolved.
Show resolved Hide resolved
<SvgIcon
class="svg-icon"
:name="collapsed ? 'octicon-chevron-right' : 'octicon-chevron-down'"
Expand Down Expand Up @@ -79,31 +79,31 @@ export default {
</script>

<style scoped>
span.svg-icon.status {
.svg-icon.status {
float: right;
}

span.svg-icon.file {
.svg-icon.file {
color: var(--color-secondary-dark-7);
}

span.svg-icon.directory {
.svg-icon.directory {
color: var(--color-primary);
}

span.svg-icon.octicon-diff-modified {
.svg-icon.octicon-diff-modified {
color: var(--color-yellow);
}

span.svg-icon.octicon-diff-added {
.svg-icon.octicon-diff-added {
color: var(--color-green);
}

span.svg-icon.octicon-diff-removed {
.svg-icon.octicon-diff-removed {
color: var(--color-red);
}

span.svg-icon.octicon-diff-renamed {
.svg-icon.octicon-diff-renamed {
color: var(--color-teal);
}

Expand Down Expand Up @@ -139,9 +139,11 @@ div.list {

a {
text-decoration: none;
color: var(--color-text);
}

a:hover {
text-decoration: none;
color: var(--color-text);
}
</style>