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

Expand selected file when clicking file tree #24041

Merged
9 changes: 9 additions & 0 deletions web_src/js/components/DiffFileTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import DiffFileTreeItem from './DiffFileTreeItem.vue';
import {doLoadMoreFiles} from '../features/repo-diff.js';
import {toggleElem} from '../utils/dom.js';
import {setFileFolding} from '../features/file-fold.js';

const {pageData} = window.config;
const LOCAL_STORAGE_KEY = 'diff_file_tree_visible';
Expand Down Expand Up @@ -103,15 +104,23 @@ export default {

this.hashChangeListener = () => {
this.selectedFile = window.location.hash;
this.expandSelectedFile();
};
this.hashListener = window.addEventListener('hashchange', this.hashChangeListener);
this.selectedFile = window.location.hash;
this.expandSelectedFile();
},
unmounted() {
document.querySelector('.diff-toggle-file-tree-button').removeEventListener('click', this.toggleVisibility);
window.removeEventListener('hashchange', this.hashChangeListener);
},
methods: {
expandSelectedFile() {
// expand file if the selected file is folded
const box = document.querySelector(this.selectedFile);
const folded = box.getAttribute('data-folded') === 'true';
if (folded) setFileFolding(box, box.querySelector('.fold-file'), false);
silverwind marked this conversation as resolved.
Show resolved Hide resolved
},
toggleVisibility() {
this.updateVisibility(!this.fileTreeIsVisible);
},
Expand Down