Skip to content

Commit

Permalink
Add the 'search.collapseResults' preference to the search-in-workspace
Browse files Browse the repository at this point in the history
Fixes #5685

Added the new preference to the search-in-workspace widget to
control the display of the tree when rendering results.

The values are the following:
- `auto`: expand all nodes except those with over 10 matches
- `alwaysCollapse`: always collapse all nodes
- `alwaysExpand`: always expand all nodes

Aligned the setting with vscode, previously we used 20 results,
but it's been updated to 10.

Signed-off-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Jul 12, 2019
1 parent 4535f24 commit f2681ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
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 @@ -273,6 +273,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

0 comments on commit f2681ee

Please sign in to comment.