BigW Consortium Gitlab

shortcuts_blob.js 680 Bytes
Newer Older
1 2 3
/* global Mousetrap */
/* global Shortcuts */

4
import './shortcuts';
5 6 7 8 9 10

const defaults = {
  skipResetBindings: false,
  fileBlobPermalinkUrl: null,
};

11
export default class ShortcutsBlob extends Shortcuts {
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
  constructor(opts) {
    const options = Object.assign({}, defaults, opts);
    super(options.skipResetBindings);
    this.options = options;

    Mousetrap.bind('y', this.moveToFilePermalink.bind(this));
  }

  moveToFilePermalink() {
    if (this.options.fileBlobPermalinkUrl) {
      const hash = gl.utils.getLocationHash();
      const hashUrlString = hash ? `#${hash}` : '';
      gl.utils.visitUrl(`${this.options.fileBlobPermalinkUrl}${hashUrlString}`);
    }
  }
}