Skip to content

Commit

Permalink
fix: show files on symbol link folders (#2379)
Browse files Browse the repository at this point in the history
  • Loading branch information
erha19 authored Mar 7, 2023
1 parent ad29275 commit ad721ea
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
11 changes: 7 additions & 4 deletions packages/file-tree-next/src/browser/file-tree.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,20 @@ export class FileTreeService extends Tree implements IFileTreeService {
const parentURI = new URI(childrenParentStat.uri);
const nearestParentDirectory = parent.parent as Directory;
if (parent && nearestParentDirectory) {
let parentName;
let parentName: string | undefined = parent.name;
if (parent.filestat.isSymbolicLink) {
// 当软链目录本身发生折叠时
parentName = new URI(parent.filestat.realUri).relative(parentURI)?.toString();
parentName = [parent.uri.displayName].concat(parentName.split(Path.separator)).join(Path.separator);
const relativePath = new URI(parent.filestat.realUri).relative(parentURI)?.toString();
if (relativePath) {
parentName = relativePath;
parentName = [parent.uri.displayName].concat(parentName.split(Path.separator)).join(Path.separator);
}
} else if (nearestParentDirectory.filestat.isSymbolicLink) {
parentName = new URI(nearestParentDirectory.filestat.realUri).relative(parentURI)?.toString();
} else {
parentName = nearestParentDirectory.uri.relative(parentURI)?.toString();
}
if (parentName !== parent.name) {
if (parentName && parentName !== parent.name) {
parent.updateMetaData({
name: parentName,
uri: parentURI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { IFileServiceClient } from '@opensumi/ide-file-service/lib/common';
import { IDialogService } from '@opensumi/ide-overlay';
import { IWorkspaceEditService } from '@opensumi/ide-workspace-edit';

import { IFileTreeAPI, IFileTreeService } from '../../common';
import { IFileTreeAPI, IFileTreeService, IMoveFileMetadata } from '../../common';
import { Directory, File } from '../../common/file-tree-node.define';

@Injectable()
Expand Down Expand Up @@ -98,9 +98,6 @@ export class FileTreeAPI implements IFileTreeAPI {
// labelService可根据uri参数提供不同的展示效果
const name = presetName ? presetName : uri.displayName;
let node: Directory | File;
if (!this.cacheFileStat.has(filestat.uri)) {
this.cacheFileStat.set(filestat.uri, filestat);
}
if (filestat.isDirectory) {
node = new Directory(tree as any, parent, uri, name, filestat, this.getReadableTooltip(uri));
} else {
Expand All @@ -109,18 +106,18 @@ export class FileTreeAPI implements IFileTreeAPI {
return node;
}

async mvFiles(fromFiles: URI[], targetDir: URI) {
async mvFiles(fromFiles: IMoveFileMetadata[], targetDir: URI) {
const error: string[] = [];
for (const from of fromFiles) {
if (from.isEqualOrParent(targetDir)) {
if (from.url.isEqualOrParent(targetDir)) {
return;
}
}
// 合并具有包含关系的文件移动
const sortedFiles = fromFiles.sort((a, b) => a.toString().length - b.toString().length);
const mergeFiles: URI[] = [];
const mergeFiles: IMoveFileMetadata[] = [];
for (const file of sortedFiles) {
if (mergeFiles.length > 0 && mergeFiles.find((exist) => exist.isEqualOrParent(file))) {
if (mergeFiles.length > 0 && mergeFiles.find((exist) => exist.url.isEqualOrParent(file.url))) {
continue;
}
mergeFiles.push(file);
Expand All @@ -131,7 +128,7 @@ export class FileTreeAPI implements IFileTreeAPI {
const confirm = await this.dialogService.warning(
formatLocalize(
'file.confirm.move',
`[ ${mergeFiles.map((uri) => uri.displayName).join(',')} ]`,
`[ ${mergeFiles.map((file) => file.url.displayName).join(',')} ]`,
targetDir.displayName,
),
[cancel, ok],
Expand All @@ -141,8 +138,7 @@ export class FileTreeAPI implements IFileTreeAPI {
}
}
for (const from of mergeFiles) {
const filestat = this.cacheFileStat.get(from.toString());
const res = await this.mv(from, targetDir.resolve(from.displayName), filestat && filestat.isDirectory);
const res = await this.mv(from.url, targetDir.resolve(from.url.displayName), from.isDirectory);
if (res) {
error.push(res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export class DragAndDropService extends WithEventBus {
}
if (resources.length > 0) {
const targetContainerUri = activeUri ? activeUri : (containing && containing.uri)!;
const resourcesCanBeMoved = resources.filter(
const resourcesCanBeMoved: (File | Directory)[] = resources.filter(
(resource: File | Directory) =>
resource &&
resource.parent &&
Expand All @@ -316,7 +316,7 @@ export class DragAndDropService extends WithEventBus {
if (resourcesCanBeMoved.length > 0) {
// 最小化移动文件
const errors = await this.fileTreeAPI.mvFiles(
resourcesCanBeMoved.map((res) => res.uri),
resourcesCanBeMoved.map((res) => ({ url: res.uri, isDirectory: res.filestat.isDirectory })),
targetContainerUri,
);
if (errors && errors.length > 0) {
Expand Down Expand Up @@ -347,12 +347,15 @@ export class DragAndDropService extends WithEventBus {
);
// 由于节点移动时默认仅更新节点路径
// 我们需要自己更新额外的参数,如uri, filestat等
target.updateURI(to);
target.updateFileStat({
...target.filestat,
uri: to.toString(),
target.updateMetaData({
name: to.displayName,
fileStat: {
...target.filestat,
uri: to.toString(),
},
uri: to,
tooltip: this.fileTreeAPI.getReadableTooltip(to),
});
target.updateToolTip(this.fileTreeAPI.getReadableTooltip(to));
// 当重命名文件为文件夹时,刷新文件夹更新子文件路径
if (Directory.is(target)) {
this.fileTreeService.refresh(target as Directory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,12 @@ export class FileTreeModelService {
}
}
const errors = await this.fileTreeAPI.mvFiles(
pasteStore.crossFiles ? pasteStore.crossFiles : pasteStore.files.map((file) => file.uri),
pasteStore.crossFiles
? pasteStore.crossFiles.map((url) => ({
url,
isDirectory: this.fileTreeService.getNodeByPathOrUri(url)?.filestat.isDirectory || false,
}))
: pasteStore.files.map((file) => ({ url: file.uri, isDirectory: file.filestat.isDirectory })),
parent.uri,
);
if (errors && errors.length > 0) {
Expand Down
8 changes: 7 additions & 1 deletion packages/file-tree-next/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ export const IFileTreeService = Symbol('IFileTreeService');
export interface IFileTreeService extends ITree {
refresh(): Promise<void>;
}

export interface IMoveFileMetadata {
url: URI;
isDirectory: boolean;
}

export interface IFileTreeAPI {
copyFile(from: URI, to: URI): Promise<FileStat | string | void>;
createFile(newUri: URI, content?: string): Promise<string | void>;
createDirectory(newUri: URI): Promise<string | void>;
delete(uri: URI): Promise<string | void>;
mvFiles(oldUri: URI[], newUri: URI, isDirectory?: boolean): Promise<string[] | void>;
mvFiles(oldUri: IMoveFileMetadata[], newUri: URI): Promise<string[] | void>;
mv(oldUri: URI, newUri: URI, isDirectory?: boolean): Promise<string | void>;
resolveChildren(
tree: ITree,
Expand Down

0 comments on commit ad721ea

Please sign in to comment.