Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[search-in-workspace] add the 'search.collapseResults' preference #5686

Merged
merged 1 commit into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ export const searchInWorkspacePreferencesSchema: PreferenceSchema = {
description: 'Controls whether to show line numbers for search results.',
default: false,
type: 'boolean',
},
'search.collapseResults': {
description: 'Controls whether the search results will be collapsed or expanded.',
default: 'auto',
type: 'string',
enum: ['auto', 'alwaysCollapse', 'alwaysExpand'],
}
}
};

export class SearchInWorkspaceConfiguration {
'search.lineNumbers': boolean;
'search.collapseResults': string;
}

export const SearchInWorkspacePreferences = Symbol('SearchInWorkspacePreferences');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export class SearchInWorkspaceResultTreeWidget extends TreeWidget {

async search(searchTerm: string, searchOptions: SearchInWorkspaceOptions): Promise<void> {
this.searchTerm = searchTerm;
const collapseValue: string = this.searchInWorkspacePreferences['search.collapseResults'];
this.resultTree.clear();
this.cancelIndicator.cancel();
this.cancelIndicator = new CancellationTokenSource();
Expand All @@ -222,11 +223,10 @@ export class SearchInWorkspaceResultTreeWidget extends TreeWidget {
if (fileNode.children.findIndex(lineNode => lineNode.id === line.id) < 0) {
fileNode.children.push(line);
}
if (fileNode.children.length >= 20 && fileNode.expanded) {
fileNode.expanded = false;
}
this.collapseFileNode(fileNode, collapseValue);
} else {
const newFileNode = this.createFileNode(result.root, name, path, result.fileUri, rootFolderNode);
this.collapseFileNode(newFileNode, collapseValue);
const line = this.createResultLineNode(result, newFileNode);
newFileNode.children.push(line);
rootFolderNode.children.push(newFileNode);
Expand All @@ -235,8 +235,8 @@ export class SearchInWorkspaceResultTreeWidget extends TreeWidget {
} else {
const newRootFolderNode = this.createRootFolderNode(result.root);
tree.set(result.root, newRootFolderNode);

const newFileNode = this.createFileNode(result.root, name, path, result.fileUri, newRootFolderNode);
this.collapseFileNode(newFileNode, collapseValue);
newFileNode.children.push(this.createResultLineNode(result, newFileNode));
newRootFolderNode.children.push(newFileNode);
}
Expand Down Expand Up @@ -265,6 +265,20 @@ export class SearchInWorkspaceResultTreeWidget extends TreeWidget {
}
}

/**
* Collapse the search-in-workspace file node
* based on the preference value.
*/
protected collapseFileNode(node: SearchInWorkspaceFileNode, preferenceValue: string): void {
if (preferenceValue === 'auto' && node.children.length >= 10) {
node.expanded = false;
} else if (preferenceValue === 'alwaysCollapse') {
node.expanded = false;
} else if (preferenceValue === 'alwaysExpand') {
node.expanded = true;
}
}

protected handleUp(event: KeyboardEvent): void {
if (!this.model.getPrevSelectableNode(this.model.selectedNodes[0])) {
this.focusInputEmitter.fire(true);
Expand Down