Store view state in async find (#229348)

This commit is contained in:
Benjamin Christopher Simmonds
2024-09-23 11:14:28 +02:00
committed by GitHub
parent c81de060bb
commit 3045954bf9
+13 -3
View File
@@ -395,7 +395,10 @@ class AsyncFindController<TInput, T, TFilterData> extends AbstractFindController
declare protected readonly filter: AsyncFindFilter<TInput, T>;
private readonly model: ITreeModel<IAsyncDataTreeNode<TInput, T> | null, TFilterData, IAsyncDataTreeNode<TInput, T> | null>;
private readonly nodes = new Map<null | T, IAsyncDataTreeNode<TInput, T>>();
private previousTreeScrollTop: number = 0;
private previousScrollTop: number | undefined;
private previousFocus: (IAsyncDataTreeNode<TInput, T> | null)[] = [];
private previousSelection: (IAsyncDataTreeNode<TInput, T> | null)[] = [];
private sessionId: number = 0;
private active: boolean = false;
@@ -439,7 +442,12 @@ class AsyncFindController<TInput, T, TFilterData> extends AbstractFindController
private activateFindMode(): void {
this.sessionId++;
this.previousTreeScrollTop = this.tree.scrollTop;
// store tree view state
this.previousScrollTop = this.tree.scrollTop;
this.previousFocus = this.tree.getFocus();
this.previousSelection = this.tree.getSelection();
this.tree.scrollTop = 0;
const findModel = this.tree.createNewModel({ filter: this.filter as ITreeFilter<IAsyncDataTreeNode<TInput, T> | null, TFilterData> });
this.tree.setModel(findModel);
@@ -452,7 +460,9 @@ class AsyncFindController<TInput, T, TFilterData> extends AbstractFindController
if (focus && focus.element && this.findProvider.revealResultInTree) {
this.findProvider.revealResultInTree(focus.element as T);
} else {
this.tree.scrollTop = this.previousTreeScrollTop;
this.tree.scrollTop = this.previousScrollTop ?? 0;
this.tree.setFocus(this.previousFocus);
this.tree.setSelection(this.previousSelection);
}
this.activeTokenSource = undefined;