[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:
ameer2468 2023-10-23 17:48:49 +03:00 committed by GitHub
parent 46397010e4
commit 3d0991a76e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 0 deletions

View file

@ -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>

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

View file

@ -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: {