shortcuts_blob.js 672 Bytes
Newer Older
1 2
/* global Mousetrap */

3
import Shortcuts from './shortcuts';
4 5 6 7 8 9

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

10
export default class ShortcutsBlob extends Shortcuts {
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
  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}`);
    }
  }
}