Skip to content

Commit 8a10c1e

Browse files
authored
Merge pull request #103 from beNative/codex/fix-folder-overview-visibility
Ensure folder overview activates after adding folders
2 parents 45ea467 + a2a7dbe commit 8a10c1e

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

App.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,11 +991,12 @@ const MainApp: React.FC = () => {
991991

992992
useEffect(() => {
993993
const documentIds = new Set(items.filter(item => item.type === 'document').map(item => item.id));
994+
const allItemIds = new Set(items.map(item => item.id));
994995
setTabState(prev => {
995996
const filteredOrder = prev.order.filter(id => documentIds.has(id));
996997
const orderChanged = filteredOrder.length !== prev.order.length;
997998
let nextActive = prev.activeId;
998-
if (nextActive && !documentIds.has(nextActive)) {
999+
if (nextActive && !allItemIds.has(nextActive)) {
9991000
nextActive = filteredOrder[filteredOrder.length - 1] ?? null;
10001001
}
10011002
if (!orderChanged && nextActive === prev.activeId) {
@@ -2009,6 +2010,7 @@ const MainApp: React.FC = () => {
20092010
{ id: 'new-document', name: 'Create New Document', action: () => handleNewDocument(), category: 'File', icon: PlusIcon, shortcut: ['Control', 'N'], keywords: 'add create file' },
20102011
{ id: 'new-code-file', name: 'Create New Code File', action: handleOpenNewCodeFileModal, category: 'File', icon: CodeIcon, shortcut: ['Control', 'Shift', 'N'], keywords: 'add create script' },
20112012
{ id: 'new-folder', name: 'Create New Folder', action: handleNewRootFolder, category: 'File', icon: FolderPlusIcon, keywords: 'add create directory' },
2013+
{ id: 'new-subfolder', name: 'Create New Subfolder', action: handleNewSubfolder, category: 'File', icon: FolderDownIcon, keywords: 'add create directory child' },
20122014
{ id: 'new-template', name: 'Create New Template', action: handleNewTemplate, category: 'File', icon: DocumentDuplicateIcon, keywords: 'add create template' },
20132015
{ id: 'new-from-template', name: 'New Document from Template...', action: () => { addLog('INFO', 'Command: New Document from Template.'); setCreateFromTemplateOpen(true); }, category: 'File', icon: DocumentDuplicateIcon, keywords: 'add create file instance' },
20142016
{ id: 'duplicate-item', name: 'Duplicate Selection', action: handleDuplicateSelection, category: 'File', icon: CopyIcon, keywords: 'copy clone' },
@@ -2020,7 +2022,7 @@ const MainApp: React.FC = () => {
20202022
{ id: 'toggle-info', name: 'Toggle Info View', action: () => { addLog('INFO', 'Command: Toggle Info View.'); setView(v => v === 'info' ? 'editor' : 'info'); }, category: 'View', icon: InfoIcon, keywords: 'help docs readme' },
20212023
{ id: 'open-about', name: 'About DocForge', action: handleOpenAbout, category: 'Help', icon: SparklesIcon, keywords: 'about credits information' },
20222024
{ id: 'toggle-logs', name: 'Toggle Logs Panel', action: () => { addLog('INFO', 'Command: Toggle Logs Panel.'); setIsLoggerVisible(v => !v); }, category: 'View', icon: TerminalIcon, keywords: 'debug console' },
2023-
], [handleNewDocument, handleOpenNewCodeFileModal, handleNewRootFolder, handleDeleteSelection, handleNewTemplate, toggleSettingsView, handleDuplicateSelection, selectedIds, addLog, handleToggleCommandPalette, handleFormatDocument, handleOpenAbout]);
2025+
], [handleNewDocument, handleOpenNewCodeFileModal, handleNewRootFolder, handleNewSubfolder, handleDeleteSelection, handleNewTemplate, toggleSettingsView, handleDuplicateSelection, selectedIds, addLog, handleToggleCommandPalette, handleFormatDocument, handleOpenAbout]);
20242026

20252027
const enrichedCommands = useMemo(() => {
20262028
return commands.map(command => {

components/Sidebar.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import DocumentList from './PromptList';
44
import TemplateList from './TemplateList';
55
import type { DocumentOrFolder, DocumentTemplate, Command, DraggedNodeTransfer } from '../types';
66
import IconButton from './IconButton';
7-
import { FolderPlusIcon, PlusIcon, SearchIcon, DocumentDuplicateIcon, ChevronDownIcon, ChevronRightIcon, ExpandAllIcon, CollapseAllIcon, CodeIcon, XIcon } from './Icons';
7+
import { FolderPlusIcon, PlusIcon, SearchIcon, DocumentDuplicateIcon, ChevronDownIcon, ChevronRightIcon, ExpandAllIcon, CollapseAllIcon, CodeIcon, XIcon, FolderDownIcon } from './Icons';
88
import { DocumentNode } from './PromptTreeItem';
99
import { storageService } from '../services/storageService';
1010
import { LOCAL_STORAGE_KEYS } from '../constants';
@@ -84,6 +84,14 @@ const Sidebar: React.FC<SidebarProps> = (props) => {
8484

8585
const openDocumentIdSet = useMemo(() => new Set(props.openDocumentIds), [props.openDocumentIds]);
8686

87+
const canCreateSubfolder = useMemo(() => {
88+
if (!props.activeNodeId) {
89+
return false;
90+
}
91+
const activeItem = props.documents.find(item => item.id === props.activeNodeId);
92+
return activeItem?.type === 'folder' ?? false;
93+
}, [props.documents, props.activeNodeId]);
94+
8795

8896
const sidebarRef = useRef<HTMLDivElement>(null);
8997
const isResizingTemplates = useRef(false);
@@ -371,6 +379,16 @@ const Sidebar: React.FC<SidebarProps> = (props) => {
371379
<IconButton onClick={props.onNewCodeFile} tooltip={getTooltip('new-code-file', 'New Code File')} size="xs" tooltipPosition="bottom">
372380
<CodeIcon className="w-4 h-4" />
373381
</IconButton>
382+
<IconButton
383+
onClick={props.onNewSubfolder}
384+
tooltip={canCreateSubfolder ? getTooltip('new-subfolder', 'New Subfolder') : 'Select a folder to add a subfolder'}
385+
size="xs"
386+
tooltipPosition="bottom"
387+
disabled={!canCreateSubfolder}
388+
className={!canCreateSubfolder ? 'opacity-40 cursor-not-allowed' : ''}
389+
>
390+
<FolderDownIcon className="w-4 h-4" />
391+
</IconButton>
374392
<IconButton onClick={props.onNewRootFolder} tooltip={getTooltip('new-folder', 'New Root Folder')} size="xs" tooltipPosition="bottom">
375393
<FolderPlusIcon className="w-4 h-4" />
376394
</IconButton>

0 commit comments

Comments
 (0)