2018-03-17 18:26:18 +05:30
|
|
|
import Mousetrap from 'mousetrap';
|
|
|
|
import { getLocationHash, visitUrl } from './lib/utils/url_utility';
|
|
|
|
import Shortcuts from './shortcuts';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
const defaults = {
|
|
|
|
skipResetBindings: false,
|
|
|
|
fileBlobPermalinkUrl: null,
|
|
|
|
};
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
export default class ShortcutsBlob extends Shortcuts {
|
2017-08-17 22:00:37 +05:30
|
|
|
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) {
|
2018-03-17 18:26:18 +05:30
|
|
|
const hash = getLocationHash();
|
2017-08-17 22:00:37 +05:30
|
|
|
const hashUrlString = hash ? `#${hash}` : '';
|
2018-03-17 18:26:18 +05:30
|
|
|
visitUrl(`${this.options.fileBlobPermalinkUrl}${hashUrlString}`);
|
2016-09-13 17:45:13 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
}
|