Welcome to mirror list, hosted at ThFree Co, Russian Federation.

shortcuts_find_file.js « shortcuts « behaviors « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f0d2ecfd2102aea29fb9c522c865df9a91a2ebb0 (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
import Mousetrap from 'mousetrap';
import ShortcutsNavigation from './shortcuts_navigation';

export default class ShortcutsFindFile extends ShortcutsNavigation {
  constructor(projectFindFile) {
    super();

    const oldStopCallback = Mousetrap.prototype.stopCallback;

    Mousetrap.prototype.stopCallback = function customStopCallback(e, element, combo) {
      if (
        element === 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.call(this, e, element, combo);
    };

    Mousetrap.bind('up', projectFindFile.selectRowUp);
    Mousetrap.bind('down', projectFindFile.selectRowDown);
    Mousetrap.bind('esc', projectFindFile.goToTree);
    Mousetrap.bind('enter', projectFindFile.goToBlob);
  }
}