diff options
author | Mike Greiling <mike@pixelcog.com> | 2018-09-18 15:34:14 -0500 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2018-09-18 17:26:15 -0500 |
commit | 196dfd2627fec6c0ede1d7df0dd49881b2bbd898 (patch) | |
tree | 530ba14b7ab2560f11335b1bfe9daa2bb3079efd /app/assets/javascripts/behaviors/shortcuts/shortcuts_find_file.js | |
parent | 08c3920ce14628e90244fba5f580ca4d7bdabdbd (diff) | |
download | gitlab-ce-196dfd2627fec6c0ede1d7df0dd49881b2bbd898.tar.gz |
Move shortcuts classes into behaviors/shortcuts
Diffstat (limited to 'app/assets/javascripts/behaviors/shortcuts/shortcuts_find_file.js')
-rw-r--r-- | app/assets/javascripts/behaviors/shortcuts/shortcuts_find_file.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/assets/javascripts/behaviors/shortcuts/shortcuts_find_file.js b/app/assets/javascripts/behaviors/shortcuts/shortcuts_find_file.js new file mode 100644 index 00000000000..8658081c6c2 --- /dev/null +++ b/app/assets/javascripts/behaviors/shortcuts/shortcuts_find_file.js @@ -0,0 +1,29 @@ +import Mousetrap from 'mousetrap'; +import ShortcutsNavigation from './shortcuts_navigation'; + +export default class ShortcutsFindFile extends ShortcutsNavigation { + constructor(projectFindFile) { + super(); + + const oldStopCallback = Mousetrap.stopCallback; + this.projectFindFile = projectFindFile; + + Mousetrap.stopCallback = (e, element, combo) => { + if ( + element === this.projectFindFile.inputElement[0] && + (combo === 'up' || combo === 'down' || combo === 'esc' || combo === 'enter') + ) { + // when press up/down key in textbox, cursor prevent to move to home/end + e.preventDefault(); + return false; + } + + return oldStopCallback(e, element, combo); + }; + + Mousetrap.bind('up', this.projectFindFile.selectRowUp); + Mousetrap.bind('down', this.projectFindFile.selectRowDown); + Mousetrap.bind('esc', this.projectFindFile.goToTree); + Mousetrap.bind('enter', this.projectFindFile.goToBlob); + } +} |