Skip to content

Commit

Permalink
feat: update comment and saveAs
Browse files Browse the repository at this point in the history
  • Loading branch information
hui2334387208 committed Dec 26, 2024
1 parent a1ccf50 commit c6d064c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
6 changes: 0 additions & 6 deletions packages/editor/src/common/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,8 @@ export abstract class WorkbenchEditorService {
*/
abstract openUris(uri: URI[]): Promise<void>;

/**
* 保存
*/
abstract save(): Promise<void>;

/**
* 保存
*/
abstract saveAs(uri: URI): Promise<URI | undefined>;

/**
Expand Down
30 changes: 18 additions & 12 deletions packages/file-tree-next/src/browser/dialog/file-dialog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,11 @@ export class FileTreeDialogService extends Tree {
get contextKey() {
return this.fileDialogContextKey;
}

async saveAs(options: { oldFilePath: string; newFilePath: string }) {
await this.createFile({
...options,
});
// TODO: 不依赖 workspaceEditor,先关闭再打开,等 fileSystemProvider 迁移到前端再做改造
await this.workbenchEditorService.open(URI.file(options.newFilePath), {
await this.createFile(options);
const openUri: URI = URI.file(options.newFilePath);
await this.workbenchEditorService.open(openUri, {
preview: false,
focus: true,
replace: true,
Expand All @@ -151,13 +150,20 @@ export class FileTreeDialogService extends Tree {
}

async createFile(options: { oldFilePath: string; newFilePath: string }) {
const { oldFilePath, newFilePath } = options;
const { content } = await this.fileServiceClient.readFile(oldFilePath);
await this.fileServiceClient.createFile(newFilePath, {
content: content.toString(),
encoding: 'utf8',
overwrite: true,
});
try {
const { oldFilePath, newFilePath } = options;
let fileStat = await this.fileServiceClient.getFileStat(oldFilePath);
if (fileStat) {
const { content } = await this.fileServiceClient.readFile(oldFilePath);
await this.fileServiceClient.createFile(newFilePath, {
content: content.toString(),
encoding: 'utf8',
overwrite: true,
});
}
} catch (e) {
throw new Error(e);
}
}

dispose() {
Expand Down

0 comments on commit c6d064c

Please sign in to comment.