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:
Kristina 2022-04-26 06:31:13 -05:00 committed by GitHub
parent 9df26c7b7c
commit 090afc9ae0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View File

@ -49,7 +49,7 @@ export class KeybindingSrv {
this.bind('t r', () => toggleTheme(true));
}
private globalEsc() {
globalEsc() {
const anyDoc = document as any;
const activeElement = anyDoc.activeElement;

View File

@ -33,8 +33,7 @@ import getGlobalActions from './actions/global.static.actions';
export const CommandPalette = () => {
const styles = useStyles2(getSearchStyles);
const [actions, setActions] = useState<Action[]>([]);
const { notHidden, query, showing } = useKBar((state) => ({
notHidden: state.visualState !== VisualState.hidden,
const { query, showing } = useKBar((state) => ({
showing: state.visualState === VisualState.showing,
}));
const isNotLogin = locationService.getLocation().pathname !== '/login';
@ -45,12 +44,6 @@ export const CommandPalette = () => {
};
});
keybindingSrv.bind('esc', () => {
if (notHidden) {
query.setVisualState(VisualState.animatingOut);
}
});
useEffect(() => {
(async () => {
if (isNotLogin) {
@ -65,7 +58,18 @@ export const CommandPalette = () => {
useEffect(() => {
if (showing) {
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]);
useRegisterActions(actions, [actions]);