update ITreeElement with ICompressedTreeElement (#23839) (#23852)

This commit is contained in:
Maddy
2023-07-13 13:51:34 -07:00
committed by GitHub
parent 8e1a288d99
commit 1acc00679e

View File

@@ -37,7 +37,8 @@ import { MessageType } from 'vs/base/browser/ui/inputbox/inputBox';
import * as aria from 'vs/base/browser/ui/aria/aria';
import * as errors from 'vs/base/common/errors';
import { NotebookSearchWidget } from 'sql/workbench/contrib/notebook/browser/notebookExplorer/notebookSearchWidget';
import { ITreeElement, ITreeContextMenuEvent } from 'vs/base/browser/ui/tree/tree';
import { ICompressedTreeElement } from 'vs/base/browser/ui/tree/compressedObjectTreeModel';
import { ITreeContextMenuEvent, ObjectTreeElementCollapseState } from 'vs/base/browser/ui/tree/tree';
import { Iterable } from 'vs/base/common/iterator';
import { searchClearIcon, searchCollapseAllIcon, searchExpandAllIcon, searchStopIcon } from 'vs/workbench/contrib/search/browser/searchIcons';
import { Action, IAction } from 'vs/base/common/actions';
@@ -430,45 +431,49 @@ export class NotebookSearchView extends SearchView {
return false;
}
private createSearchResultIterator(collapseResults: ISearchConfigurationProperties['collapseResults']): Iterable<ITreeElement<RenderableMatch>> {
private createSearchResultIterator(collapseResults: ISearchConfigurationProperties['collapseResults']): Iterable<ICompressedTreeElement<RenderableMatch>> {
const folderMatches = this.searchResult.folderMatches()
.filter(fm => !fm.isEmpty())
.sort(searchMatchComparer);
if (folderMatches.length === 1) {
return this.createSearchFolderIterator(folderMatches[0], collapseResults);
return this.createSearchFolderIterator(folderMatches[0], collapseResults, true);
}
return Iterable.map(folderMatches, folderMatch => {
const children = this.createSearchFolderIterator(folderMatch, collapseResults);
return <ITreeElement<RenderableMatch>>{ element: folderMatch, children };
const children = this.createSearchFolderIterator(folderMatch, collapseResults, true);
return <ICompressedTreeElement<RenderableMatch>>{ element: folderMatch, children };
});
}
private createSearchFolderIterator(folderMatch: FolderMatch, collapseResults: ISearchConfigurationProperties['collapseResults']): Iterable<ITreeElement<RenderableMatch>> {
private createSearchFolderIterator(folderMatch: FolderMatch, collapseResults: ISearchConfigurationProperties['collapseResults'], childFolderIncompressible: boolean): Iterable<ICompressedTreeElement<RenderableMatch>> {
const sortOrder = this.searchConfig.sortOrder;
const matches = folderMatch.matches().sort((a, b) => searchMatchComparer(a, b, sortOrder));
return Iterable.map(matches, fileMatch => {
//const children = this.createFileIterator(fileMatch);
let nodeExists = true;
try { this.tree.getNode(fileMatch); } catch (e) { nodeExists = false; }
const matchArray = this.isTreeLayoutViewVisible ? folderMatch.matches() : folderMatch.allDownstreamFileMatches();
const matches = matchArray.sort((a, b) => searchMatchComparer(a, b, sortOrder));
const collapsed = nodeExists ? undefined :
(collapseResults === 'alwaysCollapse' || (fileMatch.matches().length > 10 && collapseResults !== 'alwaysExpand'));
return Iterable.map(matches, match => {
let children;
if (match instanceof FileMatch) {
children = this.createSearchFileIterator(match);
} else {
children = this.createSearchFolderIterator(match, collapseResults, false);
}
return <ITreeElement<RenderableMatch>>{ element: fileMatch, undefined, collapsed, collapsible: false };
const collapsed = (collapseResults === 'alwaysCollapse' || (match.count() > 10 && collapseResults !== 'alwaysExpand')) ? ObjectTreeElementCollapseState.PreserveOrCollapsed : ObjectTreeElementCollapseState.PreserveOrExpanded;
return <ICompressedTreeElement<RenderableMatch>>{ element: match, children, collapsed, incompressible: (match instanceof FileMatch) ? true : childFolderIncompressible };
});
}
private createSearchFileIterator(fileMatch: FileMatch): Iterable<ITreeElement<RenderableMatch>> {
private createSearchFileIterator(fileMatch: FileMatch): Iterable<ICompressedTreeElement<RenderableMatch>> {
const matches = fileMatch.matches().sort(searchMatchComparer);
return Iterable.map(matches, r => (<ITreeElement<RenderableMatch>>{ element: r }));
return Iterable.map(matches, r => (<ICompressedTreeElement<RenderableMatch>>{ element: r }));
}
private createSearchIterator(match: FolderMatch | FileMatch | SearchResult, collapseResults: ISearchConfigurationProperties['collapseResults']): Iterable<ITreeElement<RenderableMatch>> {
private createSearchIterator(match: FolderMatch | FileMatch | SearchResult, collapseResults: ISearchConfigurationProperties['collapseResults']): Iterable<ICompressedTreeElement<RenderableMatch>> {
return match instanceof SearchResult ? this.createSearchResultIterator(collapseResults) :
match instanceof FolderMatch ? this.createSearchFolderIterator(match, collapseResults) :
match instanceof FolderMatch ? this.createSearchFolderIterator(match, collapseResults, false) :
this.createSearchFileIterator(match);
}