From dfff4c5e8e461d48c57a6ce380de8bd72fae1eb6 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Wed, 24 May 2017 15:46:59 -0700 Subject: [PATCH] Fix #26634 - if a `./` include pattern contains glob characters, ignore the `./` --- .../search/browser/patternInputWidget.ts | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/parts/search/browser/patternInputWidget.ts b/src/vs/workbench/parts/search/browser/patternInputWidget.ts index 75bef0a6f43..0657073ca2f 100644 --- a/src/vs/workbench/parts/search/browser/patternInputWidget.ts +++ b/src/vs/workbench/parts/search/browser/patternInputWidget.ts @@ -110,8 +110,6 @@ export class PatternInputWidget extends Widget { return {}; } - const isSearchPath = segment => segment.match(/^\.\//); - let exprSegments: string[]; let searchPaths: string[]; if (isGlobPattern) { @@ -119,21 +117,17 @@ export class PatternInputWidget extends Widget { .map(s => s.trim()) .filter(s => !!s.length); - const groups = collections.groupBy(segments, - segment => isSearchPath(segment) ? 'searchPaths' : 'exprSegments'); - searchPaths = groups.searchPaths || []; - exprSegments = groups.exprSegments || []; + const groups = this.groupByPathsAndExprSegments(segments); + searchPaths = groups.searchPaths; + exprSegments = groups.exprSegments; } else { const segments = pattern.split(',') .map(s => strings.trim(s.trim(), '/')) .filter(s => !!s.length); - const groups = collections.groupBy(segments, - segment => isSearchPath(segment) ? 'searchPaths' : 'exprSegments'); - searchPaths = groups.searchPaths || []; - exprSegments = groups.exprSegments || []; - - exprSegments = exprSegments + const groups = this.groupByPathsAndExprSegments(segments); + searchPaths = groups.searchPaths; + exprSegments = groups.exprSegments .map(p => { if (p[0] === '.') { p = '*' + p; // convert ".js" to "*.js" @@ -147,6 +141,27 @@ export class PatternInputWidget extends Widget { return { expression, searchPaths }; } + private groupByPathsAndExprSegments(segments: string[]) { + const isSearchPath = segment => segment.match(/^\.\//); + + const groups = collections.groupBy(segments, + segment => isSearchPath(segment) ? 'searchPaths' : 'exprSegments'); + groups.searchPaths = groups.searchPaths || []; + groups.exprSegments = groups.exprSegments || []; + + // If a ./searchPath has a glob character, remove ./ and use it as an expression segment + groups.searchPaths = groups.searchPaths.filter(searchPath => { + if (searchPath.match(/[\*\{\}\(\)\[\]\?]/)) { + groups.exprSegments.push(strings.ltrim(searchPath, './')); + return false; + } + + return true; + }); + + return groups; + } + public select(): void { this.inputBox.select(); } -- GitLab