summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/shortcuts_find_file.js
blob: 81286c0010ca04f5c2b6174f0eee5e072d4adaa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* global 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, cusor prevent to move to home/end
        event.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);
  }
}