File tree Expand file tree Collapse file tree 3 files changed +25
-68
lines changed
Expand file tree Collapse file tree 3 files changed +25
-68
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';
33import { createPortal } from 'react-dom' ;
44import { Icon , Input } from '@ui5/webcomponents-react' ;
55import { K8sResource } from 'types' ;
6+ import { useEventListener } from 'hooks/useEventListener' ;
67import { useObjectState } from 'shared/useObjectState' ;
78import { CommandPaletteUI } from './CommandPaletteUI' ;
89import { useRecoilValue } from 'recoil' ;
@@ -44,6 +45,29 @@ export function CommandPaletteSearchBar({
4445 }
4546 } ;
4647
48+ const onKeyPress = ( e : Event ) => {
49+ const { key, metaKey, ctrlKey } = e as KeyboardEvent ;
50+ // for (Edge, Chrome) || (Firefox, Safari)
51+ const isMac = (
52+ ( navigator as any ) . userAgentData ?. platform || navigator . platform
53+ )
54+ ?. toLowerCase ( )
55+ ?. startsWith ( 'mac' ) ;
56+ const modifierKeyPressed = ( isMac && metaKey ) || ( ! isMac && ctrlKey ) ;
57+
58+ if (
59+ ( key === 'k' || key === 'K' ) &&
60+ modifierKeyPressed &&
61+ window . location . pathname !== '/clusters'
62+ ) {
63+ setShowDialog ( ! shouldShowDialog ) ;
64+ // [on Firefox] prevent opening the browser search bar via CMD/CTRL+K
65+ e . preventDefault ( ) ;
66+ }
67+ } ;
68+
69+ useEventListener ( 'keydown' , onKeyPress , [ shouldShowDialog ] ) ;
70+
4771 useEffect ( ( ) => {
4872 setShellbarWidth (
4973 showCompanion . show
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ import { savePreviousPath } from 'state/useAfterInitHook';
99
1010import App from './components/App/App' ;
1111import { Spinner } from 'shared/components/Spinner/Spinner' ;
12- import { CommandPaletteProvider } from 'command-pallette/CommandPaletteProvider' ;
1312import { NotificationProvider } from 'shared/contexts/NotificationContext' ;
1413
1514import { ThemeProvider } from '@ui5/webcomponents-react' ;
@@ -65,9 +64,7 @@ root.render(
6564 < BrowserRouter >
6665 < Suspense fallback = { < Spinner /> } >
6766 < NotificationProvider >
68- < CommandPaletteProvider >
69- < App />
70- </ CommandPaletteProvider >
67+ < App />
7168 </ NotificationProvider >
7269 </ Suspense >
7370 </ BrowserRouter >
You can’t perform that action at this time.
0 commit comments