diff --git a/frontend/src/modules/ide/components/FileExplorer.tsx b/frontend/src/modules/ide/components/FileExplorer.tsx index a798bfc..529dd40 100644 --- a/frontend/src/modules/ide/components/FileExplorer.tsx +++ b/frontend/src/modules/ide/components/FileExplorer.tsx @@ -56,8 +56,10 @@ export const FileExplorer: React.FC = ({ }; const filteredFiles = store.searchQuery - ? filterTree(files, store.searchQuery) - : files; + ? (files.children || []) + .map((child) => filterTree(child, store.searchQuery)) + .filter((child): child is FileNode => child !== null) + : files.children || []; useEffect(() => { if (store.searchQuery && files) { @@ -185,29 +187,6 @@ export const FileExplorer: React.FC = ({ -
- - - {files.name} - -
- {showSearch && (
= ({ )}
- {filteredFiles ? ( - + {filteredFiles.length > 0 ? ( + filteredFiles.map((child, idx) => ( + + )) ) : (
= ({ files }) => { backgroundColor: "var(--bg-primary)", }} > - + {(files.children || []).map((child, idx) => ( + + ))}
); }; diff --git a/frontend/src/modules/ide/store/useIDEStore.ts b/frontend/src/modules/ide/store/useIDEStore.ts index 47ee7e3..7c566aa 100644 --- a/frontend/src/modules/ide/store/useIDEStore.ts +++ b/frontend/src/modules/ide/store/useIDEStore.ts @@ -442,6 +442,7 @@ export const useIDEStore = create((set, get) => ({ return; } + // Определяем родительский путь let parentPath: string; if (!dialog.node) { parentPath = ""; @@ -453,17 +454,44 @@ export const useIDEStore = create((set, get) => ({ parentPath = pathParts.join("/"); } - const fullPath = parentPath ? `${parentPath}/${value}` : value; + // Проверяем наличие расширения + const hasExtension = + value.includes(".") && value.split(".").pop() !== value; + let finalName = value; + let isFile = false; + + // Если диалог создания файла + if (dialog.type === "newFile") { + isFile = true; + // Если нет расширения — добавляем .txt + if (!hasExtension) { + finalName = `${value}.txt`; + } + } else if (dialog.type === "newFolder") { + // Если диалог создания папки — но имя с расширением, считаем файлом + if (hasExtension) { + isFile = true; + } + } + + const fullPath = parentPath ? `${parentPath}/${finalName}` : finalName; + + // Сохраняем раскрытые папки ДО перезагрузки дерева + const savedExpandedFolders = new Set(get().expandedFolders); try { const result = await scriptsApi.createScript({ content: "", - interpreter_id: 0, + interpreter_id: 1, path: fullPath, }); await get().fetchTree(); + // Восстанавливаем раскрытые папки + set({ expandedFolders: savedExpandedFolders }); + + // Собираем все пути от корня до родительской папки const allParentPaths: string[] = []; let current = parentPath; while (current) { @@ -472,17 +500,14 @@ export const useIDEStore = create((set, get) => ({ parts.pop(); current = parts.join("/"); } - allParentPaths.forEach((p) => { - if (!get().expandedFolders.has(p)) { - toggleFolder(p); - } - }); + + // Раскрываем родительскую цепочку autoExpandPaths(new Set(allParentPaths)); - if (dialog.type === "newFile") { + if (isFile) { const createdNode: FileNode = { id: result.id, - name: value, + name: finalName, type: "file", content: result.content, path: result.path,