diff --git a/src/vs/workbench/parts/search/browser/searchViewlet.ts b/src/vs/workbench/parts/search/browser/searchViewlet.ts index 15fb889aed7..c3bd5272e28 100644 --- a/src/vs/workbench/parts/search/browser/searchViewlet.ts +++ b/src/vs/workbench/parts/search/browser/searchViewlet.ts @@ -893,13 +893,33 @@ export class SearchViewlet extends Viewlet { } public searchInFolder(resource: URI): void { + let folderPath = null; + const workspace = this.contextService.getWorkspace2(); + if (workspace) { + if (workspace.roots.length === 1) { + // Fallback to old way for single root workspace + folderPath = this.contextService.toWorkspaceRelativePath(resource); + if (folderPath && folderPath !== '.') { + folderPath = './' + folderPath; + } + } else { + folderPath = resource.fsPath; + } + } + + if (!folderPath || folderPath === '.') { + this.inputPatternIncludes.setValue(''); + this.searchWidget.focus(); + return; + } + // Show 'files to include' box if (!this.showsFileTypes()) { this.toggleQueryDetails(true, true); } this.inputPatternIncludes.setIsGlobPattern(false); - this.inputPatternIncludes.setValue(resource.fsPath); + this.inputPatternIncludes.setValue(folderPath); this.searchWidget.focus(false); }