2017-12-19 05:12:32 -05:00
|
|
|
import Mousetrap from 'mousetrap';
|
2017-12-07 07:30:53 -05:00
|
|
|
import { getLocationHash, visitUrl } from './lib/utils/url_utility';
|
2017-10-10 05:10:11 -04:00
|
|
|
import Shortcuts from './shortcuts';
|
2017-01-25 22:13:01 -05:00
|
|
|
|
|
|
|
const defaults = {
|
|
|
|
skipResetBindings: false,
|
|
|
|
fileBlobPermalinkUrl: null,
|
|
|
|
};
|
|
|
|
|
2017-05-16 18:06:34 -04:00
|
|
|
export default class ShortcutsBlob extends Shortcuts {
|
2017-01-25 22:13:01 -05:00
|
|
|
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) {
|
2017-12-07 07:30:53 -05:00
|
|
|
const hash = getLocationHash();
|
2017-01-25 22:13:01 -05:00
|
|
|
const hashUrlString = hash ? `#${hash}` : '';
|
2017-12-07 07:30:53 -05:00
|
|
|
visitUrl(`${this.options.fileBlobPermalinkUrl}${hashUrlString}`);
|
2017-01-25 22:13:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|