Skip to content

Commit 4fa0890

Browse files
authored
Merge pull request microsoft#79294 from LeuisKen/master
fix: keep the two "Copy Path" behavior consistent
2 parents 759d117 + 92399b7 commit 4fa0890

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/vs/workbench/contrib/search/browser/searchActions.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ import * as DOM from 'vs/base/browser/dom';
77
import { Action } from 'vs/base/common/actions';
88
import { INavigator } from 'vs/base/common/iterator';
99
import { createKeybinding, ResolvedKeybinding } from 'vs/base/common/keyCodes';
10-
import { normalizeDriveLetter } from 'vs/base/common/labels';
11-
import { Schemas } from 'vs/base/common/network';
12-
import { normalize } from 'vs/base/common/path';
1310
import { isWindows, OS } from 'vs/base/common/platform';
1411
import { repeat } from 'vs/base/common/strings';
15-
import { URI } from 'vs/base/common/uri';
1612
import * as nls from 'vs/nls';
1713
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
14+
import { ILabelService } from 'vs/platform/label/common/label';
1815
import { ICommandHandler } from 'vs/platform/commands/common/commands';
1916
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2017
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
@@ -667,14 +664,11 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
667664
}
668665
}
669666

670-
function uriToClipboardString(resource: URI): string {
671-
return resource.scheme === Schemas.file ? normalize(normalizeDriveLetter(resource.fsPath)) : resource.toString();
672-
}
673-
674667
export const copyPathCommand: ICommandHandler = async (accessor, fileMatch: FileMatch | FolderMatch) => {
675668
const clipboardService = accessor.get(IClipboardService);
669+
const labelService = accessor.get(ILabelService);
676670

677-
const text = uriToClipboardString(fileMatch.resource);
671+
const text = labelService.getUriLabel(fileMatch.resource, { noPrefix: true });
678672
await clipboardService.writeText(text);
679673
};
680674

@@ -706,25 +700,26 @@ function matchToString(match: Match, indent = 0): string {
706700
}
707701

708702
const lineDelimiter = isWindows ? '\r\n' : '\n';
709-
function fileMatchToString(fileMatch: FileMatch, maxMatches: number): { text: string, count: number } {
703+
function fileMatchToString(fileMatch: FileMatch, maxMatches: number, labelService: ILabelService): { text: string, count: number } {
710704
const matchTextRows = fileMatch.matches()
711705
.sort(searchMatchComparer)
712706
.slice(0, maxMatches)
713707
.map(match => matchToString(match, 2));
708+
const uriString = labelService.getUriLabel(fileMatch.resource, { noPrefix: true });
714709
return {
715-
text: `${uriToClipboardString(fileMatch.resource)}${lineDelimiter}${matchTextRows.join(lineDelimiter)}`,
710+
text: `${uriString}${lineDelimiter}${matchTextRows.join(lineDelimiter)}`,
716711
count: matchTextRows.length
717712
};
718713
}
719714

720-
function folderMatchToString(folderMatch: FolderMatch | BaseFolderMatch, maxMatches: number): { text: string, count: number } {
715+
function folderMatchToString(folderMatch: FolderMatch | BaseFolderMatch, maxMatches: number, labelService: ILabelService): { text: string, count: number } {
721716
const fileResults: string[] = [];
722717
let numMatches = 0;
723718

724719
const matches = folderMatch.matches().sort(searchMatchComparer);
725720

726721
for (let i = 0; i < folderMatch.fileCount() && numMatches < maxMatches; i++) {
727-
const fileResult = fileMatchToString(matches[i], maxMatches - numMatches);
722+
const fileResult = fileMatchToString(matches[i], maxMatches - numMatches, labelService);
728723
numMatches += fileResult.count;
729724
fileResults.push(fileResult.text);
730725
}
@@ -738,27 +733,28 @@ function folderMatchToString(folderMatch: FolderMatch | BaseFolderMatch, maxMatc
738733
const maxClipboardMatches = 1e4;
739734
export const copyMatchCommand: ICommandHandler = async (accessor, match: RenderableMatch) => {
740735
const clipboardService = accessor.get(IClipboardService);
736+
const labelService = accessor.get(ILabelService);
741737

742738
let text: string | undefined;
743739
if (match instanceof Match) {
744740
text = matchToString(match);
745741
} else if (match instanceof FileMatch) {
746-
text = fileMatchToString(match, maxClipboardMatches).text;
742+
text = fileMatchToString(match, maxClipboardMatches, labelService).text;
747743
} else if (match instanceof BaseFolderMatch) {
748-
text = folderMatchToString(match, maxClipboardMatches).text;
744+
text = folderMatchToString(match, maxClipboardMatches, labelService).text;
749745
}
750746

751747
if (text) {
752748
await clipboardService.writeText(text);
753749
}
754750
};
755751

756-
function allFolderMatchesToString(folderMatches: Array<FolderMatch | BaseFolderMatch>, maxMatches: number): string {
752+
function allFolderMatchesToString(folderMatches: Array<FolderMatch | BaseFolderMatch>, maxMatches: number, labelService: ILabelService): string {
757753
const folderResults: string[] = [];
758754
let numMatches = 0;
759755
folderMatches = folderMatches.sort(searchMatchComparer);
760756
for (let i = 0; i < folderMatches.length && numMatches < maxMatches; i++) {
761-
const folderResult = folderMatchToString(folderMatches[i], maxMatches - numMatches);
757+
const folderResult = folderMatchToString(folderMatches[i], maxMatches - numMatches, labelService);
762758
if (folderResult.count) {
763759
numMatches += folderResult.count;
764760
folderResults.push(folderResult.text);
@@ -772,12 +768,13 @@ export const copyAllCommand: ICommandHandler = async (accessor) => {
772768
const viewletService = accessor.get(IViewletService);
773769
const panelService = accessor.get(IPanelService);
774770
const clipboardService = accessor.get(IClipboardService);
771+
const labelService = accessor.get(ILabelService);
775772

776773
const searchView = getSearchView(viewletService, panelService);
777774
if (searchView) {
778775
const root = searchView.searchResult;
779776

780-
const text = allFolderMatchesToString(root.folderMatches(), maxClipboardMatches);
777+
const text = allFolderMatchesToString(root.folderMatches(), maxClipboardMatches, labelService);
781778
await clipboardService.writeText(text);
782779
}
783780
};

0 commit comments

Comments
 (0)