mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
Merge pull request #79294 from LeuisKen/master
fix: keep the two "Copy Path" behavior consistent
This commit is contained in:
@@ -7,14 +7,11 @@ import * as DOM from 'vs/base/browser/dom';
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
import { INavigator } from 'vs/base/common/iterator';
|
||||
import { createKeybinding, ResolvedKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { normalizeDriveLetter } from 'vs/base/common/labels';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { normalize } from 'vs/base/common/path';
|
||||
import { isWindows, OS } from 'vs/base/common/platform';
|
||||
import { repeat } from 'vs/base/common/strings';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import * as nls from 'vs/nls';
|
||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import { ILabelService } from 'vs/platform/label/common/label';
|
||||
import { ICommandHandler } from 'vs/platform/commands/common/commands';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
@@ -667,14 +664,11 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
|
||||
}
|
||||
}
|
||||
|
||||
function uriToClipboardString(resource: URI): string {
|
||||
return resource.scheme === Schemas.file ? normalize(normalizeDriveLetter(resource.fsPath)) : resource.toString();
|
||||
}
|
||||
|
||||
export const copyPathCommand: ICommandHandler = async (accessor, fileMatch: FileMatch | FolderMatch) => {
|
||||
const clipboardService = accessor.get(IClipboardService);
|
||||
const labelService = accessor.get(ILabelService);
|
||||
|
||||
const text = uriToClipboardString(fileMatch.resource);
|
||||
const text = labelService.getUriLabel(fileMatch.resource, { noPrefix: true });
|
||||
await clipboardService.writeText(text);
|
||||
};
|
||||
|
||||
@@ -706,25 +700,26 @@ function matchToString(match: Match, indent = 0): string {
|
||||
}
|
||||
|
||||
const lineDelimiter = isWindows ? '\r\n' : '\n';
|
||||
function fileMatchToString(fileMatch: FileMatch, maxMatches: number): { text: string, count: number } {
|
||||
function fileMatchToString(fileMatch: FileMatch, maxMatches: number, labelService: ILabelService): { text: string, count: number } {
|
||||
const matchTextRows = fileMatch.matches()
|
||||
.sort(searchMatchComparer)
|
||||
.slice(0, maxMatches)
|
||||
.map(match => matchToString(match, 2));
|
||||
const uriString = labelService.getUriLabel(fileMatch.resource, { noPrefix: true });
|
||||
return {
|
||||
text: `${uriToClipboardString(fileMatch.resource)}${lineDelimiter}${matchTextRows.join(lineDelimiter)}`,
|
||||
text: `${uriString}${lineDelimiter}${matchTextRows.join(lineDelimiter)}`,
|
||||
count: matchTextRows.length
|
||||
};
|
||||
}
|
||||
|
||||
function folderMatchToString(folderMatch: FolderMatch | BaseFolderMatch, maxMatches: number): { text: string, count: number } {
|
||||
function folderMatchToString(folderMatch: FolderMatch | BaseFolderMatch, maxMatches: number, labelService: ILabelService): { text: string, count: number } {
|
||||
const fileResults: string[] = [];
|
||||
let numMatches = 0;
|
||||
|
||||
const matches = folderMatch.matches().sort(searchMatchComparer);
|
||||
|
||||
for (let i = 0; i < folderMatch.fileCount() && numMatches < maxMatches; i++) {
|
||||
const fileResult = fileMatchToString(matches[i], maxMatches - numMatches);
|
||||
const fileResult = fileMatchToString(matches[i], maxMatches - numMatches, labelService);
|
||||
numMatches += fileResult.count;
|
||||
fileResults.push(fileResult.text);
|
||||
}
|
||||
@@ -738,14 +733,15 @@ function folderMatchToString(folderMatch: FolderMatch | BaseFolderMatch, maxMatc
|
||||
const maxClipboardMatches = 1e4;
|
||||
export const copyMatchCommand: ICommandHandler = async (accessor, match: RenderableMatch) => {
|
||||
const clipboardService = accessor.get(IClipboardService);
|
||||
const labelService = accessor.get(ILabelService);
|
||||
|
||||
let text: string | undefined;
|
||||
if (match instanceof Match) {
|
||||
text = matchToString(match);
|
||||
} else if (match instanceof FileMatch) {
|
||||
text = fileMatchToString(match, maxClipboardMatches).text;
|
||||
text = fileMatchToString(match, maxClipboardMatches, labelService).text;
|
||||
} else if (match instanceof BaseFolderMatch) {
|
||||
text = folderMatchToString(match, maxClipboardMatches).text;
|
||||
text = folderMatchToString(match, maxClipboardMatches, labelService).text;
|
||||
}
|
||||
|
||||
if (text) {
|
||||
@@ -753,12 +749,12 @@ export const copyMatchCommand: ICommandHandler = async (accessor, match: Rendera
|
||||
}
|
||||
};
|
||||
|
||||
function allFolderMatchesToString(folderMatches: Array<FolderMatch | BaseFolderMatch>, maxMatches: number): string {
|
||||
function allFolderMatchesToString(folderMatches: Array<FolderMatch | BaseFolderMatch>, maxMatches: number, labelService: ILabelService): string {
|
||||
const folderResults: string[] = [];
|
||||
let numMatches = 0;
|
||||
folderMatches = folderMatches.sort(searchMatchComparer);
|
||||
for (let i = 0; i < folderMatches.length && numMatches < maxMatches; i++) {
|
||||
const folderResult = folderMatchToString(folderMatches[i], maxMatches - numMatches);
|
||||
const folderResult = folderMatchToString(folderMatches[i], maxMatches - numMatches, labelService);
|
||||
if (folderResult.count) {
|
||||
numMatches += folderResult.count;
|
||||
folderResults.push(folderResult.text);
|
||||
@@ -772,12 +768,13 @@ export const copyAllCommand: ICommandHandler = async (accessor) => {
|
||||
const viewletService = accessor.get(IViewletService);
|
||||
const panelService = accessor.get(IPanelService);
|
||||
const clipboardService = accessor.get(IClipboardService);
|
||||
const labelService = accessor.get(ILabelService);
|
||||
|
||||
const searchView = getSearchView(viewletService, panelService);
|
||||
if (searchView) {
|
||||
const root = searchView.searchResult;
|
||||
|
||||
const text = allFolderMatchesToString(root.folderMatches(), maxClipboardMatches);
|
||||
const text = allFolderMatchesToString(root.folderMatches(), maxClipboardMatches, labelService);
|
||||
await clipboardService.writeText(text);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user