diff options
author | Denys Mishunov <dmishunov@gitlab.com> | 2019-02-27 09:12:13 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-02-27 09:12:13 +0000 |
commit | 0aff8e27530d391e4c819838b46d77f6231ecf70 (patch) | |
tree | 994b53c9de178e06dfca697044c231651749a369 /app/assets/javascripts/diffs/store/getters.js | |
parent | d40a3809fd387f8dc9a28218a004260b600a1412 (diff) | |
download | gitlab-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.js | 7 |
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 () => {}; |