mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-14 12:24:04 +00:00
[ENG-1354] Shortcut to reveal in finder/explorer (#1665)
* Shortcut to reveal in finder/explorer * Update useKeyRevealFinder.ts * update keybinds page * move hook * fix import paths
This commit is contained in:
parent
46397010e4
commit
3d0991a76e
|
@ -11,6 +11,7 @@ import DismissibleNotice from './DismissibleNotice';
|
|||
import { Inspector, INSPECTOR_WIDTH } from './Inspector';
|
||||
import ExplorerContextMenu from './ParentContextMenu';
|
||||
import { useExplorerStore } from './store';
|
||||
import { useKeyRevealFinder } from './useKeyRevealFinder';
|
||||
import View, { EmptyNotice, ExplorerViewProps } from './View';
|
||||
import { ExplorerPath, PATH_BAR_HEIGHT } from './View/ExplorerPath';
|
||||
|
||||
|
@ -57,6 +58,8 @@ export default function Explorer(props: PropsWithChildren<Props>) {
|
|||
explorer.settingsStore.showHiddenFiles = !explorer.settingsStore.showHiddenFiles;
|
||||
});
|
||||
|
||||
useKeyRevealFinder();
|
||||
|
||||
return (
|
||||
<>
|
||||
<ExplorerContextMenu>
|
||||
|
|
66
interface/app/$libraryId/Explorer/useKeyRevealFinder.ts
Normal file
66
interface/app/$libraryId/Explorer/useKeyRevealFinder.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import {useLibraryContext} from '@sd/client';
|
||||
import { usePlatform, type Platform } from '~/util/Platform';
|
||||
import { useMemo } from 'react';
|
||||
import { useKeysMatcher } from '~/hooks';
|
||||
import { useKeys } from 'rooks';
|
||||
import { useExplorerContext } from '~/app/$libraryId/Explorer/Context';
|
||||
|
||||
export const useKeyRevealFinder = () => {
|
||||
const explorer = useExplorerContext();
|
||||
const {revealItems} = usePlatform();
|
||||
const shortcuts = useKeysMatcher(['Meta'])
|
||||
const {library} = useLibraryContext();
|
||||
|
||||
const items = useMemo(() => {
|
||||
const array: Parameters<NonNullable<Platform['revealItems']>>[1] = [];
|
||||
|
||||
for (const item of explorer.selectedItems.values()) {
|
||||
switch (item.type) {
|
||||
case 'Path': {
|
||||
array.push({
|
||||
FilePath: { id: item.item.id }
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'Object': {
|
||||
// this isn't good but it's the current behaviour
|
||||
const filePath = item.item.file_paths[0];
|
||||
if (filePath)
|
||||
array.push({
|
||||
FilePath: {
|
||||
id: filePath.id
|
||||
}
|
||||
});
|
||||
else return [];
|
||||
break;
|
||||
}
|
||||
case 'Location': {
|
||||
array.push({
|
||||
Location: {
|
||||
id: item.item.id
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'NonIndexedPath': {
|
||||
array.push({
|
||||
Ephemeral: {
|
||||
path: item.item.path
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}, [explorer.selectedItems]);
|
||||
|
||||
useKeys([shortcuts.Meta.key, 'KeyY'], (e) => {
|
||||
e.stopPropagation();
|
||||
if (!revealItems) return;
|
||||
revealItems(
|
||||
library.uuid,
|
||||
items
|
||||
);
|
||||
});
|
||||
}
|
|
@ -186,6 +186,17 @@ const shortcutCategories: Record<string, Shortcut[]> = {
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
action: 'Reveal in Explorer/Finder',
|
||||
keys: {
|
||||
macOS: {
|
||||
value: [modifierSymbols.Meta.macOS, 'Y']
|
||||
},
|
||||
all: {
|
||||
value: [modifierSymbols.Control.Other, 'Y']
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
action: 'Rename file or folder',
|
||||
keys: {
|
||||
|
|
Loading…
Reference in a new issue