debian-mirror-gitlab/app/assets/javascripts/shortcuts_find_file.js

30 lines
972 B
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Mousetrap from 'mousetrap';
import ShortcutsNavigation from './shortcuts_navigation';
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
export default class ShortcutsFindFile extends ShortcutsNavigation {
constructor(projectFindFile) {
super();
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
const oldStopCallback = Mousetrap.stopCallback;
this.projectFindFile = projectFindFile;
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
Mousetrap.stopCallback = (e, element, combo) => {
if (
element === this.projectFindFile.inputElement[0] &&
(combo === 'up' || combo === 'down' || combo === 'esc' || combo === 'enter')
) {
2018-11-08 19:23:39 +05:30
// when press up/down key in textbox, cursor prevent to move to home/end
e.preventDefault();
2018-03-17 18:26:18 +05:30
return false;
}
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
return oldStopCallback(e, element, combo);
};
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
Mousetrap.bind('up', this.projectFindFile.selectRowUp);
Mousetrap.bind('down', this.projectFindFile.selectRowDown);
Mousetrap.bind('esc', this.projectFindFile.goToTree);
Mousetrap.bind('enter', this.projectFindFile.goToBlob);
}
}