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:
parent
ea967fd6c7
commit
a73ba551db
3 changed files with 25 additions and 18 deletions
|
|
@ -89,8 +89,9 @@ export const FileSectionDiff = ({
|
||||||
return writeSnippets[writeSnippets.length - 1].newString;
|
return writeSnippets[writeSnippets.length - 1].newString;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const hasCodeMirrorContent =
|
// Show CodeMirror whenever we have resolved modified content (including new files
|
||||||
fileContent && fileContent.contentSource !== 'unavailable' && resolvedModified !== null;
|
// where contentSource may be 'unavailable' but write-new snippet provides the content)
|
||||||
|
const hasCodeMirrorContent = resolvedModified !== null;
|
||||||
|
|
||||||
if (!hasCodeMirrorContent) {
|
if (!hasCodeMirrorContent) {
|
||||||
return (
|
return (
|
||||||
|
|
@ -105,12 +106,12 @@ export const FileSectionDiff = ({
|
||||||
<div className="overflow-auto">
|
<div className="overflow-auto">
|
||||||
<DiffErrorBoundary
|
<DiffErrorBoundary
|
||||||
filePath={file.filePath}
|
filePath={file.filePath}
|
||||||
oldString={fileContent.originalFullContent ?? ''}
|
oldString={fileContent?.originalFullContent ?? ''}
|
||||||
newString={resolvedModified}
|
newString={resolvedModified}
|
||||||
>
|
>
|
||||||
<CodeMirrorDiffView
|
<CodeMirrorDiffView
|
||||||
key={`${file.filePath}:${discardCounter}`}
|
key={`${file.filePath}:${discardCounter}`}
|
||||||
original={fileContent.originalFullContent ?? ''}
|
original={fileContent?.originalFullContent ?? ''}
|
||||||
modified={resolvedModified}
|
modified={resolvedModified}
|
||||||
fileName={file.relativePath}
|
fileName={file.relativePath}
|
||||||
readOnly={false}
|
readOnly={false}
|
||||||
|
|
|
||||||
|
|
@ -81,19 +81,6 @@ export const ReviewDiffContent = ({ file }: ReviewDiffContentProps) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4 p-4">
|
<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 */}
|
{/* Snippets */}
|
||||||
{nonErrorSnippets.map((snippet, index) => (
|
{nonErrorSnippets.map((snippet, index) => (
|
||||||
<SnippetDiffView key={snippet.toolUseId} snippet={snippet} index={index} />
|
<SnippetDiffView key={snippet.toolUseId} snippet={snippet} index={index} />
|
||||||
|
|
|
||||||
|
|
@ -860,7 +860,26 @@ async function refreshDirectory(
|
||||||
try {
|
try {
|
||||||
const result = await api.editor.readDir(dirPath);
|
const result = await api.editor.readDir(dirPath);
|
||||||
const currentTree = get().editorFileTree;
|
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);
|
const updatedTree = mergeChildrenIntoTree(currentTree, dirPath, result.entries);
|
||||||
set({ editorFileTree: updatedTree });
|
set({ editorFileTree: updatedTree });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue