Skip to content

Commit 964a022

Browse files
workspace: return stat when executing the rename command (#12278)
Closes #12101 The commit updates the `rename` command for files and folders to return the `stat` when a resource is successfully renamed, and `undefined` otherwise. Signed-off-by: FernandoAscencio <[email protected]>
1 parent f82e52b commit 964a022

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

packages/workspace/src/browser/workspace-commands.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -278,33 +278,32 @@ export class WorkspaceCommandContribution implements CommandContribution {
278278
registry.registerCommand(WorkspaceCommands.FILE_RENAME, this.newMultiUriAwareCommandHandler({
279279
isEnabled: uris => uris.some(uri => !this.isWorkspaceRoot(uri)) && uris.length === 1,
280280
isVisible: uris => uris.some(uri => !this.isWorkspaceRoot(uri)) && uris.length === 1,
281-
execute: (uris): void => {
282-
uris.forEach(async uri => {
283-
const parent = await this.getParent(uri);
284-
if (parent) {
285-
const oldName = uri.path.base;
286-
const dialog = new SingleTextInputDialog({
287-
title: nls.localizeByDefault('Rename'),
288-
initialValue: oldName,
289-
initialSelectionRange: {
290-
start: 0,
291-
end: uri.path.name.length
292-
},
293-
validate: async (newName, mode) => {
294-
if (oldName === newName && mode === 'preview') {
295-
return false;
296-
}
297-
return this.validateFileRename(oldName, newName, parent);
281+
execute: async uris => {
282+
const uri = uris[0]; /* Since there is only one item in the array. */
283+
const parent = await this.getParent(uri);
284+
if (parent) {
285+
const oldName = uri.path.base;
286+
const dialog = new SingleTextInputDialog({
287+
title: nls.localizeByDefault('Rename'),
288+
initialValue: oldName,
289+
initialSelectionRange: {
290+
start: 0,
291+
end: uri.path.name.length
292+
},
293+
validate: async (newName, mode) => {
294+
if (oldName === newName && mode === 'preview') {
295+
return false;
298296
}
299-
});
300-
const fileName = await dialog.open();
301-
if (fileName) {
302-
const oldUri = uri;
303-
const newUri = uri.parent.resolve(fileName);
304-
this.fileService.move(oldUri, newUri);
297+
return this.validateFileRename(oldName, newName, parent);
305298
}
299+
});
300+
const fileName = await dialog.open();
301+
if (fileName) {
302+
const oldUri = uri;
303+
const newUri = uri.parent.resolve(fileName);
304+
return this.fileService.move(oldUri, newUri);
306305
}
307-
});
306+
}
308307
}
309308
}));
310309
registry.registerCommand(WorkspaceCommands.FILE_DUPLICATE, this.newMultiUriAwareCommandHandler(this.duplicateHandler));

0 commit comments

Comments
 (0)