From 89fd45ff99129a4fadd537c9f031074a593376cb Mon Sep 17 00:00:00 2001 From: Nigel Westbury Date: Tue, 15 Sep 2020 09:53:38 +0100 Subject: [PATCH] Fixes to the tree expansion busy indicator Signed-off-by: Nigel Westbury --- packages/core/src/browser/tree/tree.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/core/src/browser/tree/tree.ts b/packages/core/src/browser/tree/tree.ts index 924cb3cd0f796..be364927215ae 100644 --- a/packages/core/src/browser/tree/tree.ts +++ b/packages/core/src/browser/tree/tree.ts @@ -359,26 +359,33 @@ export class TreeImpl implements Tree { async markAsBusy(raw: TreeNode, ms: number, token: CancellationToken): Promise { const node = this.validateNode(raw); if (node) { - await this.markAsBusy(node, ms, token); + await this.doMarkAsBusy(node, ms, token); } } protected async doMarkAsBusy(node: Mutable, ms: number, token: CancellationToken): Promise { try { await timeout(ms, token); - this.doSetBusy(node, true); - token.onCancellationRequested(() => this.doSetBusy(node, false)); + this.doSetBusy(node); + token.onCancellationRequested(() => this.doResetBusy(node)); } catch { /* no-op */ } } - protected doSetBusy(node: Mutable, busy: boolean): void { + protected doSetBusy(node: Mutable): void { const oldBusy = node.busy || 0; - const newBusy = oldBusy + (busy ? 1 : oldBusy ? -1 : 0); - if (!!oldBusy === !!newBusy) { - return; + node.busy = oldBusy + 1; + if (oldBusy === 0) { + this.onDidChangeBusyEmitter.fire(node); + } + } + protected doResetBusy(node: Mutable): void { + const oldBusy = node.busy || 0; + if (oldBusy > 0) { + node.busy = oldBusy - 1; + if (node.busy === 0) { + this.onDidChangeBusyEmitter.fire(node); + } } - node.busy = newBusy; - this.onDidChangeBusyEmitter.fire(node); } }