Skip to content

Commit d722d9a

Browse files
committed
1 parent bfcdaae commit d722d9a

1 file changed

Lines changed: 25 additions & 13 deletions

File tree

src/vs/workbench/contrib/files/browser/fileActions.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ CommandsRegistry.registerCommand({
997997
handler: downloadFileHandler
998998
});
999999

1000-
export const pasteFileHandler = (accessor: ServicesAccessor) => {
1000+
export const pasteFileHandler = async (accessor: ServicesAccessor) => {
10011001
const listService = accessor.get(IListService);
10021002
const clipboardService = accessor.get(IClipboardService);
10031003
const explorerService = accessor.get(IExplorerService);
@@ -1012,13 +1012,14 @@ export const pasteFileHandler = (accessor: ServicesAccessor) => {
10121012
const element = explorerContext.stat || explorerService.roots[0];
10131013

10141014
// Check if target is ancestor of pasted folder
1015-
Promise.all(toPaste.map(fileToPaste => {
1015+
const stats = await Promise.all(toPaste.map(async fileToPaste => {
10161016

10171017
if (element.resource.toString() !== fileToPaste.toString() && resources.isEqualOrParent(element.resource, fileToPaste, !isLinux /* ignorecase */)) {
10181018
throw new Error(nls.localize('fileIsAncestor', "File to paste is an ancestor of the destination folder"));
10191019
}
10201020

1021-
return fileService.resolve(fileToPaste).then(fileToPasteStat => {
1021+
try {
1022+
const fileToPasteStat = await fileService.resolve(fileToPaste);
10221023

10231024
// Find target
10241025
let target: ExplorerItem;
@@ -1031,18 +1032,29 @@ export const pasteFileHandler = (accessor: ServicesAccessor) => {
10311032
const targetFile = findValidPasteFileTarget(target, { resource: fileToPaste, isDirectory: fileToPasteStat.isDirectory, allowOverwirte: pasteShouldMove });
10321033

10331034
// Move/Copy File
1034-
return pasteShouldMove ? textFileService.move(fileToPaste, targetFile) : fileService.copy(fileToPaste, targetFile);
1035-
}, error => {
1035+
if (pasteShouldMove) {
1036+
return await textFileService.move(fileToPaste, targetFile);
1037+
} else {
1038+
return await fileService.copy(fileToPaste, targetFile);
1039+
}
1040+
} catch (e) {
10361041
onError(notificationService, new Error(nls.localize('fileDeleted', "File to paste was deleted or moved meanwhile")));
1037-
});
1038-
})).then((stat) => {
1039-
if (pasteShouldMove) {
1040-
// Cut is done. Make sure to clear cut state.
1041-
explorerService.setToCopy([], false);
1042+
return undefined;
10421043
}
1043-
if (stat.length === 1 && !stat[0].isDirectory) {
1044-
editorService.openEditor({ resource: stat[0].resource, options: { pinned: true, preserveFocus: true } }).then(undefined, onUnexpectedError);
1044+
}));
1045+
1046+
if (pasteShouldMove) {
1047+
// Cut is done. Make sure to clear cut state.
1048+
explorerService.setToCopy([], false);
1049+
}
1050+
if (stats.length === 1) {
1051+
const stat = stats[0];
1052+
if (stat) {
1053+
if (!stat.isDirectory) {
1054+
await editorService.openEditor({ resource: stat.resource, options: { pinned: true, preserveFocus: true } });
1055+
}
1056+
await explorerService.select(stat.resource);
10451057
}
1046-
});
1058+
}
10471059
}
10481060
};

0 commit comments

Comments
 (0)