Register shortcuts on window instead of globally
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ef2a86e7a8
commit
78413c1ecf
28
desktop/flipper-ui-core/src/utils/registerShortcut.tsx
Normal file
28
desktop/flipper-ui-core/src/utils/registerShortcut.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user