fix: render new files via CodeMirror and fix root drop refresh

- FileSectionDiff: show CodeMirror for new files even when contentSource
  is 'unavailable' — write-new snippets provide the content
- ReviewDiffContent: remove duplicate file header (already in FileSectionHeader)
- editorSlice: fix refreshDirectory for project root — tree is the root's
  children array, not a nested entry, so merge must replace top-level
This commit is contained in:
iliya 2026-03-01 13:47:30 +02:00
parent ea967fd6c7
commit a73ba551db
3 changed files with 25 additions and 18 deletions

View file

@ -89,8 +89,9 @@ export const FileSectionDiff = ({
return writeSnippets[writeSnippets.length - 1].newString;
})();
const hasCodeMirrorContent =
fileContent && fileContent.contentSource !== 'unavailable' && resolvedModified !== null;
// Show CodeMirror whenever we have resolved modified content (including new files
// where contentSource may be 'unavailable' but write-new snippet provides the content)
const hasCodeMirrorContent = resolvedModified !== null;
if (!hasCodeMirrorContent) {
return (
@ -105,12 +106,12 @@ export const FileSectionDiff = ({
<div className="overflow-auto">
<DiffErrorBoundary
filePath={file.filePath}
oldString={fileContent.originalFullContent ?? ''}
oldString={fileContent?.originalFullContent ?? ''}
newString={resolvedModified}
>
<CodeMirrorDiffView
key={`${file.filePath}:${discardCounter}`}
original={fileContent.originalFullContent ?? ''}
original={fileContent?.originalFullContent ?? ''}
modified={resolvedModified}
fileName={file.relativePath}
readOnly={false}

View file

@ -81,19 +81,6 @@ export const ReviewDiffContent = ({ file }: ReviewDiffContentProps) => {
return (
<div className="space-y-4 p-4">
{/* Заголовок файла */}
<div className="flex items-center gap-2">
<span className="text-sm font-medium text-text">{file.relativePath}</span>
{file.isNewFile && (
<span className="rounded bg-green-500/20 px-1.5 py-0.5 text-[10px] text-green-400">
NEW
</span>
)}
<span className="ml-auto text-xs text-text-muted">
{nonErrorSnippets.length} change{nonErrorSnippets.length !== 1 ? 's' : ''}
</span>
</div>
{/* Snippets */}
{nonErrorSnippets.map((snippet, index) => (
<SnippetDiffView key={snippet.toolUseId} snippet={snippet} index={index} />

View file

@ -860,7 +860,26 @@ async function refreshDirectory(
try {
const result = await api.editor.readDir(dirPath);
const currentTree = get().editorFileTree;
if (currentTree) {
if (!currentTree) return;
const projectPath = get().editorProjectPath;
if (dirPath === projectPath) {
// Root refresh — tree IS the root's children, so preserve expanded subtrees
// by merging new entries with existing children data
const existingByPath = new Map<string, FileTreeEntry>();
for (const entry of currentTree) {
existingByPath.set(entry.path, entry);
}
const merged = result.entries.map((entry) => {
const existing = existingByPath.get(entry.path);
// Preserve expanded subtree children for directories that still exist
if (existing?.children && entry.type === 'directory') {
return { ...entry, children: existing.children };
}
return entry;
});
set({ editorFileTree: merged });
} else {
const updatedTree = mergeChildrenIntoTree(currentTree, dirPath, result.entries);
set({ editorFileTree: updatedTree });
}