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)); 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;

View File

@ -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]);