Summary: Changelog: Register shortcuts only for Flipper application instead of globally. Fixes https://github.com/facebook/flipper/issues/3090 As reported, during decapitation we accidentally started registering shortcuts globally, rather per app as it used to be in the menu's. This diff fixes that and also makes sure shortcuts are supported in the browser version of flipper Reviewed By: lawrencelomax Differential Revision: D33158445 fbshipit-source-id: 8371e5b96e772152eeb93ba990e1f5edb9e67085
29 lines
763 B
TypeScript
29 lines
763 B
TypeScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
import hotkeys from 'hotkeys-js';
|
|
|
|
export function registerShortcut(
|
|
accelerator: string,
|
|
handler: () => void,
|
|
): () => void {
|
|
// normalize between Electron defined shortcuts format, and hotkeys format
|
|
// split acceleratos like Shift+CmdOrCtrl+Z into Shift+Cmd+Z,Shift+Control+Z
|
|
if (accelerator.includes('CmdOrCtrl')) {
|
|
accelerator =
|
|
accelerator.replace('CmdOrCtrl', 'Cmd') +
|
|
',' +
|
|
accelerator.replace('CmdOrCtrl', 'Ctrl');
|
|
}
|
|
hotkeys(accelerator, handler);
|
|
return () => {
|
|
hotkeys.unbind(accelerator, handler);
|
|
};
|
|
}
|