[ENG-1702] Fix space for command palette (#2269)

* Fix space for command palette

* Update index.tsx
This commit is contained in:
ameer2468 2024-04-01 21:30:44 +03:00 committed by GitHub
parent 862cd05c27
commit 12f15fc96f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 14 deletions

View file

@ -21,6 +21,7 @@ import Sparkles from '~/components/Sparkles';
import { useLocale, useShortcut } from '~/hooks';
import { usePlatform } from '~/util/Platform';
import { useQuickPreviewStore } from '../../Explorer/QuickPreview/store';
import { explorerStore } from '../../Explorer/store';
import { AddLocationDialog } from '../../settings/library/locations/AddLocationDialog';
import { openDirectoryPickerDialog } from '../../settings/library/locations/openDirectoryPickerDialog';
@ -30,13 +31,14 @@ import CMDKTags from './pages/CMDKTags';
const CMDK = () => {
const [isOpen, setIsOpen] = useState<boolean>(false);
const quickPreviewStore = useQuickPreviewStore();
const platform = usePlatform();
const libraryId = useLibraryContext().library.uuid;
useShortcut('toggleCommandPalette', (e) => {
e.preventDefault();
e.stopPropagation();
if (quickPreviewStore.open) return;
setIsOpen((v) => !v);
});

View file

@ -5,7 +5,6 @@ import useResizeObserver from 'use-resize-observer';
import { useSelector } from '@sd/client';
import { Tooltip } from '@sd/ui';
import { useKeyMatcher, useLocale, useShortcut, useShowControls } from '~/hooks';
import { useRoutingContext } from '~/RoutingContext';
import { useTabsContext } from '~/TabsContext';
import { explorerStore } from '../Explorer/store';
@ -161,35 +160,25 @@ function Tabs() {
function useTabKeybinds(props: { addTab(): void; removeTab(index: number): void }) {
const ctx = useTabsContext()!;
const { visible } = useRoutingContext();
useShortcut('newTab', (e) => {
if (!visible) return;
e.stopPropagation();
if (e.shiftKey) return; //to prevent colliding with 'navToSettings' shortcut
props.addTab();
});
useShortcut('closeTab', (e) => {
if (!visible) return;
e.stopPropagation();
props.removeTab(ctx.tabIndex);
});
useShortcut('nextTab', (e) => {
if (!visible) return;
e.stopPropagation();
ctx.setTabIndex(Math.min(ctx.tabIndex + 1, ctx.tabs.length - 1));
});
useShortcut('previousTab', (e) => {
if (!visible) return;
e.stopPropagation();
ctx.setTabIndex(Math.max(ctx.tabIndex - 1, 0));
});
}

View file

@ -169,8 +169,9 @@ export const useShortcut = (shortcut: Shortcuts, func: (e: KeyboardEvent) => voi
// useKeys doesn't like readonly
useKeys(keys as string[], (e) => {
if (!visible) return;
if (!import.meta.env.DEV) e.preventDefault();
return func(e);
}, {
when: visible
});
};