Skip to content

Commit

Permalink
Fire onDidRemoveStatus if the status differs
Browse files Browse the repository at this point in the history
Fixes #181755
  • Loading branch information
Tyriar committed May 10, 2023
1 parent 1f8d8e9 commit 3e57f89
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/vs/workbench/contrib/terminal/browser/terminalStatusList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export interface ITerminalStatusList {

/**
* Adds a status to the list.
* @param status The status object. Ideally a single status object that does not change will be
* shared as this call will no-op if the status is already set (checked by by object reference).
* @param duration An optional duration in milliseconds of the status, when specified the status
* will remove itself when the duration elapses unless the status gets re-added.
*/
Expand Down Expand Up @@ -87,6 +89,11 @@ export class TerminalStatusList extends Disposable implements ITerminalStatusLis
const timeout = window.setTimeout(() => this.remove(status), duration);
this._statusTimeouts.set(status.id, timeout);
}
const existingStatus = this._statuses.get(status.id);
if (existingStatus && existingStatus !== status) {
this._onDidRemoveStatus.fire(existingStatus);
this._statuses.delete(existingStatus.id);
}
if (!this._statuses.has(status.id)) {
const oldPrimary = this.primary;
this._statuses.set(status.id, status);
Expand All @@ -95,11 +102,6 @@ export class TerminalStatusList extends Disposable implements ITerminalStatusLis
if (oldPrimary !== newPrimary) {
this._onDidChangePrimaryStatus.fire(newPrimary);
}
} else {
this._statuses.set(status.id, status);
// It maybe the case that status hasn't changed, there isn't a good way to check this based on
// `ITerminalStatus`, so just fire the event anyway.
this._onDidAddStatus.fire(status);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ suite('Workbench - TerminalStatusList', () => {
strictEqual(list.statuses[1].icon!.id, Codicon.zap.id, 'zap~spin should have animation removed only');
});

test('add should fire onDidRemoveStatus if same status id with a different object reference was added', () => {
const eventCalls: string[] = [];
list.onDidAddStatus(() => eventCalls.push('add'));
list.onDidRemoveStatus(() => eventCalls.push('remove'));
list.add({ id: 'test', severity: Severity.Info });
list.add({ id: 'test', severity: Severity.Info });
deepStrictEqual(eventCalls, [
'add',
'remove',
'add'
]);
});

test('remove', () => {
list.add({ id: 'info', severity: Severity.Info });
list.add({ id: 'warning', severity: Severity.Warning });
Expand Down

0 comments on commit 3e57f89

Please sign in to comment.