summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/diffs/store/getters.js
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/store/getters.js
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/store/getters.js')
-rw-r--r--app/assets/javascripts/diffs/store/getters.js7
1 files changed, 7 insertions, 0 deletions
diff --git a/app/assets/javascripts/diffs/store/getters.js b/app/assets/javascripts/diffs/store/getters.js
index 4e7e5306995..bc27e263bff 100644
--- a/app/assets/javascripts/diffs/store/getters.js
+++ b/app/assets/javascripts/diffs/store/getters.js
@@ -100,5 +100,12 @@ export const diffFilesLength = state => state.diffFiles.length;
export const getCommentFormForDiffFile = state => fileHash =>
state.commentForms.find(form => form.fileHash === fileHash);
+/**
+ * Returns index of a currently selected diff in diffFiles
+ * @returns {number}
+ */
+export const currentDiffIndex = state =>
+ Math.max(0, state.diffFiles.findIndex(diff => diff.file_hash === state.currentDiffFileId));
+
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};