diff --git a/src/components/Folder/Content.tsx b/src/components/Folder/Content.tsx index 8cf2e33..c22ab88 100644 --- a/src/components/Folder/Content.tsx +++ b/src/components/Folder/Content.tsx @@ -119,8 +119,8 @@ const FolderContent = ({ folder }: Props) => { await changeFocusedFolder(folder)} - onToggle={() => toggleFolder(folder)} + onSelect={async () => await changeFocusedFolder(folder)} + onToggleExpand={() => toggleFolder(folder)} className="ffs__folder" onContextMenu={onShowContextMenu} > diff --git a/src/components/Tag/Content.tsx b/src/components/Tag/Content.tsx index 2a3da74..a3b8224 100644 --- a/src/components/Tag/Content.tsx +++ b/src/components/Tag/Content.tsx @@ -31,6 +31,7 @@ const TagContent = ({ tag }: Props) => { unpinTag, changeFocusedTag, toggleTag, + deselectFocusedTag, } = useExplorerStore( useShallow((store) => ({ focusedTag: store.focusedTag, @@ -39,13 +40,14 @@ const TagContent = ({ tag }: Props) => { unpinTag: store.unpinTag, changeFocusedTag: store.changeFocusedTag, toggleTag: store.toggleTag, + deselectFocusedTag: store.deselectFocusedTag, })) ); const nameRef = useRef(null); const contentRef = useRef(null); - const isFocused = tag.fullPath == focusedTag?.fullPath; + const isFocused = tag.fullPath === focusedTag?.fullPath; const addPinInMenu = (menu: Menu) => { const isPinned = isTagPinned(tag); @@ -81,8 +83,9 @@ const TagContent = ({ tag }: Props) => { await changeFocusedTag(tag)} - onToggle={() => toggleTag(tag)} + onSelect={() => changeFocusedTag(tag)} + onDeselect={deselectFocusedTag} + onToggleExpand={() => toggleTag(tag)} className="ffs__tag" onContextMenu={onShowContextMenu} > diff --git a/src/components/TogglableContainer.tsx b/src/components/TogglableContainer.tsx index c9a1621..24c62c0 100644 --- a/src/components/TogglableContainer.tsx +++ b/src/components/TogglableContainer.tsx @@ -10,17 +10,19 @@ import ScrollInToViewContainer from "./ScrollInToViewContainer"; type Props = { isFocused: boolean; - onFocus: AsyncNoop; - onToggle: Noop; + onSelect: AsyncNoop | Noop; + onToggleExpand: Noop; nameRef: RefObject; children: ReactNode; + onDeselect?: AsyncNoop | Noop; } & HTMLAttributes; const TogglableContainer = ({ nameRef, isFocused, - onFocus, - onToggle, + onSelect, + onToggleExpand, children, + onDeselect, ...props }: Props) => { const { plugin } = useExplorer(); @@ -34,16 +36,22 @@ const TogglableContainer = ({ e.preventDefault(); if (!isFocused) { - await onFocus(); + await onSelect(); + } else if (onDeselect) { + onDeselect(); } - if (nameRef.current && !nameRef.current.isFocusing) { - nameRef.current.setIsFocusing(true); + if (nameRef.current) { + if (!nameRef.current.isFocusing) { + nameRef.current.setIsFocusing(true); + } else if (onDeselect) { + nameRef.current.setIsFocusing(false); + } } if (expandNodeByClick === EXPAND_NODE_ON_CLICK.LABEL) { - onToggle(); + onToggleExpand(); } else if (expandNodeByClick === EXPAND_NODE_ON_CLICK.SELECTED_LABEL) { if (nameRef.current?.isFocusing) { - onToggle(); + onToggleExpand(); } } }; diff --git a/src/store/tag/focus.ts b/src/store/tag/focus.ts index 785092b..063aff8 100644 --- a/src/store/tag/focus.ts +++ b/src/store/tag/focus.ts @@ -14,8 +14,11 @@ export interface FocusedTagSlice { isFocusedTag: (tag: TagNode) => boolean; setFocusedTagAndSave: (tag: TagNode | null) => void; - changeFocusedTag: (folder: TagNode | null) => Promise; + changeFocusedTag: (folder: TagNode | null) => void; restoreLastFocusedTag: () => void; + + clearFocusedTag: () => void; + deselectFocusedTag: () => void; } export const createFocusedTagSlice = @@ -39,7 +42,7 @@ export const createFocusedTagSlice = }); }, - changeFocusedTag: async (tag: TagNode) => { + changeFocusedTag: (tag: TagNode) => { const { focusedFile, changeToTagMode, @@ -69,4 +72,14 @@ export const createFocusedTagSlice = validate: (tag) => Boolean(tag), }); }, + + clearFocusedTag: async () => { + get().setFocusedTagAndSave(null); + }, + + deselectFocusedTag: () => { + const { clearFocusedTag, changeToAllMode } = get(); + clearFocusedTag(); + changeToAllMode(); + }, });