Skip to content

Commit e03e827

Browse files
authored
Expand selected file when clicking file tree (#24041)
Auto expand the selected file when clicking the file item of the file tree. This is consistent with Github's behavior. https://user-images.githubusercontent.com/33891828/231048124-61f180af-adba-42d7-9ffa-626e1de04aed.mov
1 parent 9717675 commit e03e827

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

web_src/js/components/DiffFileTree.vue

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import DiffFileTreeItem from './DiffFileTreeItem.vue';
1818
import {doLoadMoreFiles} from '../features/repo-diff.js';
1919
import {toggleElem} from '../utils/dom.js';
2020
import {DiffTreeStore} from '../modules/stores.js';
21+
import {setFileFolding} from '../features/file-fold.js';
2122
2223
const {pageData} = window.config;
2324
const LOCAL_STORAGE_KEY = 'diff_file_tree_visible';
@@ -104,6 +105,7 @@ export default {
104105
105106
this.hashChangeListener = () => {
106107
this.store.selectedItem = window.location.hash;
108+
this.expandSelectedFile();
107109
};
108110
this.hashChangeListener();
109111
window.addEventListener('hashchange', this.hashChangeListener);
@@ -113,6 +115,14 @@ export default {
113115
window.removeEventListener('hashchange', this.hashChangeListener);
114116
},
115117
methods: {
118+
expandSelectedFile() {
119+
// expand file if the selected file is folded
120+
if (this.store.selectedItem) {
121+
const box = document.querySelector(this.store.selectedItem);
122+
const folded = box?.getAttribute('data-folded') === 'true';
123+
if (folded) setFileFolding(box, box.querySelector('.fold-file'), false);
124+
}
125+
},
116126
toggleVisibility() {
117127
this.updateVisibility(!this.fileTreeIsVisible);
118128
},

0 commit comments

Comments
 (0)