BigW Consortium Gitlab

shortcuts_blob.js 734 Bytes
Newer Older
Phil Hughes committed
1
import Mousetrap from 'mousetrap';
2
import { getLocationHash, visitUrl } from './lib/utils/url_utility';
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
  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) {
21
      const hash = getLocationHash();
22
      const hashUrlString = hash ? `#${hash}` : '';
23
      visitUrl(`${this.options.fileBlobPermalinkUrl}${hashUrlString}`);
24 25 26
    }
  }
}