mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 11:10:48 +00:00
Fix #51467
This commit is contained in:
parent
dbeeecbaed
commit
8c17b44b4e
3 changed files with 4 additions and 105 deletions
|
@ -182,43 +182,14 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
|
|||
|
||||
const history = this.searchHistoryService.load();
|
||||
const filePatterns = this.viewletSettings['query.filePatterns'] || '';
|
||||
let patternExclusions = this.viewletSettings['query.folderExclusions'] || '';
|
||||
const patternExclusionsHistory: string[] = history.exclude || this.viewletSettings['query.folderExclusionsHistory'] || [];
|
||||
let patternIncludes = this.viewletSettings['query.folderIncludes'] || '';
|
||||
let patternIncludesHistory: string[] = history.include || this.viewletSettings['query.folderIncludesHistory'] || [];
|
||||
const patternExclusions = this.viewletSettings['query.folderExclusions'] || '';
|
||||
const patternExclusionsHistory: string[] = history.exclude || [];
|
||||
const patternIncludes = this.viewletSettings['query.folderIncludes'] || '';
|
||||
const patternIncludesHistory: string[] = history.include || [];
|
||||
const queryDetailsExpanded = this.viewletSettings['query.queryDetailsExpanded'] || '';
|
||||
const useExcludesAndIgnoreFiles = typeof this.viewletSettings['query.useExcludesAndIgnoreFiles'] === 'boolean' ?
|
||||
this.viewletSettings['query.useExcludesAndIgnoreFiles'] : true;
|
||||
|
||||
// Transition history from 1.22 combined include+exclude, to split include/exclude histories
|
||||
const patternIncludesHistoryWithoutExcludes: string[] = [];
|
||||
const patternExcludesHistoryFromIncludes: string[] = [];
|
||||
patternIncludesHistory.forEach(historyEntry => {
|
||||
const includeExclude = this.queryBuilder.parseIncludeExcludePattern(historyEntry);
|
||||
if (includeExclude.includePattern) {
|
||||
patternIncludesHistoryWithoutExcludes.push(includeExclude.includePattern);
|
||||
}
|
||||
|
||||
if (includeExclude.excludePattern) {
|
||||
patternExcludesHistoryFromIncludes.push(includeExclude.excludePattern);
|
||||
}
|
||||
});
|
||||
|
||||
patternIncludesHistory = patternIncludesHistoryWithoutExcludes;
|
||||
patternExclusionsHistory.push(...patternExcludesHistoryFromIncludes);
|
||||
|
||||
// Split combined include/exclude to split include/exclude boxes
|
||||
const includeExclude = this.queryBuilder.parseIncludeExcludePattern(patternIncludes);
|
||||
patternIncludes = includeExclude.includePattern || '';
|
||||
|
||||
if (includeExclude.excludePattern) {
|
||||
if (patternExclusions) {
|
||||
patternExclusions += ', ' + includeExclude.excludePattern;
|
||||
} else {
|
||||
patternExclusions = includeExclude.excludePattern;
|
||||
}
|
||||
}
|
||||
|
||||
this.queryDetails = dom.append(this.searchWidgetsContainerElement, $('.query-details'));
|
||||
|
||||
// Toggle query details button
|
||||
|
@ -1534,15 +1505,10 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
|
|||
this.viewletSettings['query.folderIncludes'] = patternIncludes;
|
||||
this.viewletSettings['query.useExcludesAndIgnoreFiles'] = useExcludesAndIgnoreFiles;
|
||||
|
||||
// Deprecated, remove these memento props a couple releases after 1.25
|
||||
const searchHistory = this.searchWidget.getSearchHistory();
|
||||
const replaceHistory = this.searchWidget.getReplaceHistory();
|
||||
const patternExcludesHistory = this.inputPatternExcludes.getHistory();
|
||||
const patternIncludesHistory = this.inputPatternIncludes.getHistory();
|
||||
this.viewletSettings['query.searchHistory'] = searchHistory;
|
||||
this.viewletSettings['query.replaceHistory'] = replaceHistory;
|
||||
this.viewletSettings['query.folderExclusionsHistory'] = patternExcludesHistory;
|
||||
this.viewletSettings['query.folderIncludesHistory'] = patternIncludesHistory;
|
||||
|
||||
this.searchHistoryService.save({
|
||||
search: searchHistory,
|
||||
|
|
|
@ -189,28 +189,6 @@ export class QueryBuilder {
|
|||
return Object.keys(excludeExpression).length ? excludeExpression : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper that splits positive and negative patterns from a string that combines both.
|
||||
*/
|
||||
public parseIncludeExcludePattern(pattern: string): { includePattern?: string, excludePattern?: string } {
|
||||
const grouped = collections.groupBy(
|
||||
splitGlobPattern(pattern),
|
||||
s => strings.startsWith(s, '!') ? 'excludePattern' : 'includePattern');
|
||||
|
||||
const result = {};
|
||||
if (grouped.includePattern) {
|
||||
result['includePattern'] = grouped.includePattern.join(', ');
|
||||
}
|
||||
|
||||
if (grouped.excludePattern) {
|
||||
result['excludePattern'] = grouped.excludePattern
|
||||
.map(s => strings.ltrim(s, '!'))
|
||||
.join(', ');
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private mergeExcludesFromFolderQueries(folderQueries: IFolderQuery[]): glob.IExpression | undefined {
|
||||
const mergedExcludes = folderQueries.reduce((merged: glob.IExpression, fq: IFolderQuery) => {
|
||||
if (fq.excludePattern) {
|
||||
|
|
|
@ -764,51 +764,6 @@ suite('QueryBuilder', () => {
|
|||
assert(query.sortByScore);
|
||||
});
|
||||
});
|
||||
|
||||
suite('parseIncludeExcludePattern', () => {
|
||||
test('nothing', () => {
|
||||
assert.deepEqual(
|
||||
queryBuilder.parseIncludeExcludePattern(''),
|
||||
{});
|
||||
});
|
||||
|
||||
test('includes', () => {
|
||||
assert.deepEqual(
|
||||
queryBuilder.parseIncludeExcludePattern('src'),
|
||||
{
|
||||
includePattern: 'src'
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
queryBuilder.parseIncludeExcludePattern('src, test'),
|
||||
{
|
||||
includePattern: 'src, test'
|
||||
});
|
||||
});
|
||||
|
||||
test('excludes', () => {
|
||||
assert.deepEqual(
|
||||
queryBuilder.parseIncludeExcludePattern('!src'),
|
||||
{
|
||||
excludePattern: 'src'
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
queryBuilder.parseIncludeExcludePattern('!src, !test'),
|
||||
{
|
||||
excludePattern: 'src, test'
|
||||
});
|
||||
});
|
||||
|
||||
test('includes and excludes', () => {
|
||||
assert.deepEqual(
|
||||
queryBuilder.parseIncludeExcludePattern('!src, test, !foo, bar'),
|
||||
{
|
||||
includePattern: 'test, bar',
|
||||
excludePattern: 'src, foo'
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function assertEqualQueries(actual: ISearchQuery, expected: ISearchQuery): void {
|
||||
|
|
Loading…
Reference in a new issue