mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-02 11:13:29 +00:00
[ENG-1752] Fix explorer selection reset when closing quick preview via keybind (#2373)
prevent selection reset
This commit is contained in:
parent
51c94c88e3
commit
13e4ff6107
|
@ -15,7 +15,6 @@ import { isNonEmptyObject } from '~/util';
|
|||
import { useLayoutContext } from '../../../Layout/Context';
|
||||
import { useExplorerContext } from '../../Context';
|
||||
import { getQuickPreviewStore, useQuickPreviewStore } from '../../QuickPreview/store';
|
||||
import { explorerStore } from '../../store';
|
||||
import { uniqueId } from '../../util';
|
||||
import { useExplorerViewContext } from '../Context';
|
||||
import { useDragScrollable } from '../useDragScrollable';
|
||||
|
@ -515,6 +514,10 @@ export const ListView = memo(() => {
|
|||
|
||||
useEffect(() => setRanges([]), [explorerSettings.order]);
|
||||
|
||||
useEffect(() => {
|
||||
if (explorer.selectedItems.size === 0) setRanges([]);
|
||||
}, [explorer.selectedItems]);
|
||||
|
||||
useEffect(() => {
|
||||
// Reset icon size if it's not a valid size
|
||||
if (!LIST_VIEW_ICON_SIZES[explorerSettings.listViewIconSize]) {
|
||||
|
@ -653,13 +656,6 @@ export const ListView = memo(() => {
|
|||
};
|
||||
}, [sized, isLeftMouseDown, quickPreview.open]);
|
||||
|
||||
useShortcut('explorerEscape', () => {
|
||||
if (!explorerView.selectable || explorer.selectedItems.size === 0) return;
|
||||
if (explorerStore.isCMDPOpen) return;
|
||||
explorer.resetSelectedItems([]);
|
||||
setRanges([]);
|
||||
});
|
||||
|
||||
useShortcut('explorerUp', (e) => {
|
||||
keyboardHandler(e, 'ArrowUp');
|
||||
});
|
||||
|
|
|
@ -40,10 +40,11 @@ export const View = ({ emptyNotice, ...contextProps }: ExplorerViewProps) => {
|
|||
const { explorerOperatingSystem, matchingOperatingSystem } = useExplorerOperatingSystem();
|
||||
|
||||
const explorer = useExplorerContext();
|
||||
const [isContextMenuOpen, isRenaming, drag] = useSelector(explorerStore, (s) => [
|
||||
const [isContextMenuOpen, isRenaming, drag, isCMDPOpen] = useSelector(explorerStore, (s) => [
|
||||
s.isContextMenuOpen,
|
||||
s.isRenaming,
|
||||
s.drag
|
||||
s.drag,
|
||||
s.isCMDPOpen
|
||||
]);
|
||||
const { layoutMode } = explorer.useSettingsSnapshot();
|
||||
|
||||
|
@ -59,7 +60,11 @@ export const View = ({ emptyNotice, ...contextProps }: ExplorerViewProps) => {
|
|||
const [showLoading, setShowLoading] = useState(false);
|
||||
|
||||
const selectable =
|
||||
explorer.selectable && !isContextMenuOpen && !isRenaming && !quickPreviewStore.open;
|
||||
explorer.selectable &&
|
||||
!isContextMenuOpen &&
|
||||
!isRenaming &&
|
||||
!quickPreviewStore.open &&
|
||||
!isCMDPOpen;
|
||||
|
||||
// Can stay here until we add columns view
|
||||
// Once added, the provided parent related logic should move to useExplorerDroppable
|
||||
|
@ -88,10 +93,8 @@ export const View = ({ emptyNotice, ...contextProps }: ExplorerViewProps) => {
|
|||
|
||||
useShortcuts();
|
||||
|
||||
useShortcut('explorerEscape', () => {
|
||||
if (!selectable || explorer.selectedItems.size === 0) return;
|
||||
if (explorerStore.isCMDPOpen) return;
|
||||
explorer.resetSelectedItems([]);
|
||||
useShortcut('explorerEscape', () => explorer.resetSelectedItems([]), {
|
||||
disabled: !selectable || explorer.selectedItems.size === 0
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
@ -157,7 +157,11 @@ export const shortcutsStore = valtioPersist(
|
|||
shortcuts as Record<Shortcuts, Shortcut>
|
||||
);
|
||||
|
||||
export const useShortcut = (shortcut: Shortcuts, func: (e: KeyboardEvent) => void) => {
|
||||
export const useShortcut = (
|
||||
shortcut: Shortcuts,
|
||||
func: (e: KeyboardEvent) => void,
|
||||
options: Omit<Parameters<typeof useKeys>[2], 'when'> & { disabled?: boolean } = {}
|
||||
) => {
|
||||
const os = useOperatingSystem(true);
|
||||
const shortcuts = useSnapshot(shortcutsStore);
|
||||
const { visible } = useRoutingContext();
|
||||
|
@ -175,7 +179,8 @@ export const useShortcut = (shortcut: Shortcuts, func: (e: KeyboardEvent) => voi
|
|||
return func(e);
|
||||
},
|
||||
{
|
||||
when: visible
|
||||
...options,
|
||||
when: visible && !options.disabled
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue