summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/diffs/components/app.vue
diff options
context:
space:
mode:
authorDenys Mishunov <dmishunov@gitlab.com>2019-02-27 09:12:13 +0000
committerPhil Hughes <me@iamphill.com>2019-02-27 09:12:13 +0000
commit0aff8e27530d391e4c819838b46d77f6231ecf70 (patch)
tree994b53c9de178e06dfca697044c231651749a369 /app/assets/javascripts/diffs/components/app.vue
parentd40a3809fd387f8dc9a28218a004260b600a1412 (diff)
downloadgitlab-ce-0aff8e27530d391e4c819838b46d77f6231ecf70.tar.gz
Set up basic keyboard next/previous navigation in diff list
Mousetrap is used as the help-tool to listen to keystrokes Added currentDiffIndex getter to store that holds the index of currently active diff file in the list Instead of computing it on the component, we will take advantage of it being available for all components in DiffsApp Testing keyboard navigation and jumpToFile()
Diffstat (limited to 'app/assets/javascripts/diffs/components/app.vue')
-rw-r--r--app/assets/javascripts/diffs/components/app.vue33
1 files changed, 32 insertions, 1 deletions
diff --git a/app/assets/javascripts/diffs/components/app.vue b/app/assets/javascripts/diffs/components/app.vue
index 8f47931d14a..1fc2b7fe859 100644
--- a/app/assets/javascripts/diffs/components/app.vue
+++ b/app/assets/javascripts/diffs/components/app.vue
@@ -5,6 +5,7 @@ import { __ } from '~/locale';
import createFlash from '~/flash';
import { GlLoadingIcon } from '@gitlab/ui';
import PanelResizer from '~/vue_shared/components/panel_resizer.vue';
+import Mousetrap from 'mousetrap';
import eventHub from '../../notes/event_hub';
import CompareVersions from './compare_versions.vue';
import DiffFile from './diff_file.vue';
@@ -87,7 +88,7 @@ export default {
emailPatchPath: state => state.diffs.emailPatchPath,
}),
...mapState('diffs', ['showTreeList', 'isLoading', 'startVersion']),
- ...mapGetters('diffs', ['isParallelView']),
+ ...mapGetters('diffs', ['isParallelView', 'currentDiffIndex']),
...mapGetters(['isNotesFetched', 'getNoteableData']),
targetBranch() {
return {
@@ -149,6 +150,7 @@ export default {
},
beforeDestroy() {
eventHub.$off('fetchDiffData', this.fetchData);
+ this.removeEventListeners();
},
methods: {
...mapActions(['startTaskList']),
@@ -159,6 +161,7 @@ export default {
'assignDiscussionsToDiff',
'setHighlightedRow',
'cacheTreeListWidth',
+ 'scrollToFile',
]),
fetchData() {
this.fetchDiffFiles()
@@ -197,7 +200,35 @@ export default {
this.$nextTick(() => {
window.mrTabs.resetViewContainer();
window.mrTabs.expandViewContainer(this.showTreeList);
+ this.setEventListeners();
});
+ } else {
+ this.removeEventListeners();
+ }
+ },
+ setEventListeners() {
+ Mousetrap.bind(['[', 'k', ']', 'j'], (e, combo) => {
+ switch (combo) {
+ case '[':
+ case 'k':
+ this.jumpToFile(-1);
+ break;
+ case ']':
+ case 'j':
+ this.jumpToFile(+1);
+ break;
+ default:
+ break;
+ }
+ });
+ },
+ removeEventListeners() {
+ Mousetrap.unbind(['[', 'k', ']', 'j']);
+ },
+ jumpToFile(step) {
+ const targetIndex = this.currentDiffIndex + step;
+ if (targetIndex >= 0 && targetIndex < this.diffFiles.length) {
+ this.scrollToFile(this.diffFiles[targetIndex].file_path);
}
},
},