From 25ffb3829ce61f2041a435711b45526102697a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Wed, 17 May 2023 09:13:31 +0200 Subject: [PATCH] Fix TreeView.reveal() behavior. (#12489) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #12488 contributed on behalf of STMicroelectronics Signed-off-by: Thomas Mäder --- .../plugin-ext/src/plugin/tree/tree-views.ts | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/packages/plugin-ext/src/plugin/tree/tree-views.ts b/packages/plugin-ext/src/plugin/tree/tree-views.ts index 06fa967b0fe59..8d548811621f7 100644 --- a/packages/plugin-ext/src/plugin/tree/tree-views.ts +++ b/packages/plugin-ext/src/plugin/tree/tree-views.ts @@ -247,11 +247,14 @@ class TreeViewExtImpl implements Disposable { async reveal(element: T, options?: Partial): Promise { await this.pendingRefresh; + const select = options?.select !== false; // default to true + const focus = !!options?.focus; + const expand = typeof options?.expand === 'undefined' ? false : options!.expand; const elementParentChain = await this.calculateRevealParentChain(element); if (elementParentChain) { return this.proxy.$reveal(this.treeViewId, elementParentChain, { - select: true, focus: false, expand: false, ...options + select, focus, expand, ...options }); } } @@ -308,37 +311,16 @@ class TreeViewExtImpl implements Disposable { * * @param element element to reveal */ - private async calculateRevealParentChain(element: T | undefined): Promise { + private async calculateRevealParentChain(element: T | undefined): Promise { if (!element) { // root return []; } const parent = await this.options.treeDataProvider.getParent?.(element) ?? undefined; const chain = await this.calculateRevealParentChain(parent); - if (!chain) { - // parents are inconsistent - return undefined; - } const parentId = chain.length ? chain[chain.length - 1] : ''; const treeItem = await this.options.treeDataProvider.getTreeItem(element); - if (treeItem.id) { - return chain.concat(treeItem.id); - } - const cachedParentNode = this.nodes.get(parentId); - // first try to get children length from cache since getChildren disposes old nodes, which can cause a race - // condition if command is executed together with reveal. - // If not in cache, getChildren fills this.nodes and generate ids for them which are needed later - const children = cachedParentNode?.children || await this.getChildren(parentId); - if (!children) { - // parent is inconsistent - return undefined; - } - const candidateId = this.buildTreeItemId(parentId, treeItem, false); - if (this.nodes.has(candidateId)) { - return chain.concat(candidateId); - } - // couldn't calculate consistent parent chain and id - return undefined; + return chain.concat(this.buildTreeItemId(parentId, treeItem, false)); } private getTreeItemLabel(treeItem: TreeItem): string | undefined {