Skip to content

Commit

Permalink
Remove 10k limit on copying text search results
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Dec 6, 2021
1 parent 2fd934e commit 715754b
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/vs/workbench/contrib/search/browser/searchActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,9 @@ function matchToString(match: Match, indent = 0): string {
}

const lineDelimiter = isWindows ? '\r\n' : '\n';
function fileMatchToString(fileMatch: FileMatch, maxMatches: number, labelService: ILabelService): { text: string, count: number } {
function fileMatchToString(fileMatch: FileMatch, 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 {
Expand All @@ -679,25 +678,24 @@ function fileMatchToString(fileMatch: FileMatch, maxMatches: number, labelServic
};
}

function folderMatchToString(folderMatch: FolderMatchWithResource | FolderMatch, maxMatches: number, labelService: ILabelService): { text: string, count: number } {
function folderMatchToString(folderMatch: FolderMatchWithResource | FolderMatch, 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, labelService);
matches.forEach(match => {
const fileResult = fileMatchToString(match, labelService);
numMatches += fileResult.count;
fileResults.push(fileResult.text);
}
});

return {
text: fileResults.join(lineDelimiter + lineDelimiter),
count: numMatches
};
}

const maxClipboardMatches = 1e4;
export const copyMatchCommand: ICommandHandler = async (accessor, match: RenderableMatch | undefined) => {
if (!match) {
const selection = getSelectedRow(accessor);
Expand All @@ -715,24 +713,22 @@ export const copyMatchCommand: ICommandHandler = async (accessor, match: Rendera
if (match instanceof Match) {
text = matchToString(match);
} else if (match instanceof FileMatch) {
text = fileMatchToString(match, maxClipboardMatches, labelService).text;
text = fileMatchToString(match, labelService).text;
} else if (match instanceof FolderMatch) {
text = folderMatchToString(match, maxClipboardMatches, labelService).text;
text = folderMatchToString(match, labelService).text;
}

if (text) {
await clipboardService.writeText(text);
}
};

function allFolderMatchesToString(folderMatches: Array<FolderMatchWithResource | FolderMatch>, maxMatches: number, labelService: ILabelService): string {
function allFolderMatchesToString(folderMatches: Array<FolderMatchWithResource | FolderMatch>, 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, labelService);
for (let i = 0; i < folderMatches.length; i++) {
const folderResult = folderMatchToString(folderMatches[i], labelService);
if (folderResult.count) {
numMatches += folderResult.count;
folderResults.push(folderResult.text);
}
}
Expand All @@ -755,7 +751,7 @@ export const copyAllCommand: ICommandHandler = async (accessor) => {
if (searchView) {
const root = searchView.searchResult;

const text = allFolderMatchesToString(root.folderMatches(), maxClipboardMatches, labelService);
const text = allFolderMatchesToString(root.folderMatches(), labelService);
await clipboardService.writeText(text);
}
};
Expand Down

0 comments on commit 715754b

Please sign in to comment.