mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Bind command palette specific overrides and reset when no longer relevant (#48217)
* Bind command palette specific overrides and reset when no longer relevant * Use original global escape instead of resetting the whole keybinding profile
This commit is contained in:
parent
9df26c7b7c
commit
090afc9ae0
@ -49,7 +49,7 @@ export class KeybindingSrv {
|
|||||||
this.bind('t r', () => toggleTheme(true));
|
this.bind('t r', () => toggleTheme(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
private globalEsc() {
|
globalEsc() {
|
||||||
const anyDoc = document as any;
|
const anyDoc = document as any;
|
||||||
const activeElement = anyDoc.activeElement;
|
const activeElement = anyDoc.activeElement;
|
||||||
|
|
||||||
|
@ -33,8 +33,7 @@ import getGlobalActions from './actions/global.static.actions';
|
|||||||
export const CommandPalette = () => {
|
export const CommandPalette = () => {
|
||||||
const styles = useStyles2(getSearchStyles);
|
const styles = useStyles2(getSearchStyles);
|
||||||
const [actions, setActions] = useState<Action[]>([]);
|
const [actions, setActions] = useState<Action[]>([]);
|
||||||
const { notHidden, query, showing } = useKBar((state) => ({
|
const { query, showing } = useKBar((state) => ({
|
||||||
notHidden: state.visualState !== VisualState.hidden,
|
|
||||||
showing: state.visualState === VisualState.showing,
|
showing: state.visualState === VisualState.showing,
|
||||||
}));
|
}));
|
||||||
const isNotLogin = locationService.getLocation().pathname !== '/login';
|
const isNotLogin = locationService.getLocation().pathname !== '/login';
|
||||||
@ -45,12 +44,6 @@ export const CommandPalette = () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
keybindingSrv.bind('esc', () => {
|
|
||||||
if (notHidden) {
|
|
||||||
query.setVisualState(VisualState.animatingOut);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
if (isNotLogin) {
|
if (isNotLogin) {
|
||||||
@ -65,7 +58,18 @@ export const CommandPalette = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (showing) {
|
if (showing) {
|
||||||
reportInteraction('commandPalette_opened');
|
reportInteraction('commandPalette_opened');
|
||||||
|
|
||||||
|
keybindingSrv.bindGlobal('esc', () => {
|
||||||
|
query.setVisualState(VisualState.animatingOut);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
keybindingSrv.bindGlobal('esc', () => {
|
||||||
|
keybindingSrv.globalEsc();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [showing]);
|
}, [showing]);
|
||||||
|
|
||||||
useRegisterActions(actions, [actions]);
|
useRegisterActions(actions, [actions]);
|
||||||
|
Loading…
Reference in New Issue
Block a user