Skip to content

Commit d289165

Browse files
authored
Merge pull request microsoft#182067 from microsoft/tyriar/181755
Fire onDidRemoveStatus if the status differs
2 parents b3efe98 + 3e57f89 commit d289165

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/vs/workbench/contrib/terminal/browser/terminalStatusList.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export interface ITerminalStatusList {
3838

3939
/**
4040
* Adds a status to the list.
41+
* @param status The status object. Ideally a single status object that does not change will be
42+
* shared as this call will no-op if the status is already set (checked by by object reference).
4143
* @param duration An optional duration in milliseconds of the status, when specified the status
4244
* will remove itself when the duration elapses unless the status gets re-added.
4345
*/
@@ -87,6 +89,11 @@ export class TerminalStatusList extends Disposable implements ITerminalStatusLis
8789
const timeout = window.setTimeout(() => this.remove(status), duration);
8890
this._statusTimeouts.set(status.id, timeout);
8991
}
92+
const existingStatus = this._statuses.get(status.id);
93+
if (existingStatus && existingStatus !== status) {
94+
this._onDidRemoveStatus.fire(existingStatus);
95+
this._statuses.delete(existingStatus.id);
96+
}
9097
if (!this._statuses.has(status.id)) {
9198
const oldPrimary = this.primary;
9299
this._statuses.set(status.id, status);
@@ -95,11 +102,6 @@ export class TerminalStatusList extends Disposable implements ITerminalStatusLis
95102
if (oldPrimary !== newPrimary) {
96103
this._onDidChangePrimaryStatus.fire(newPrimary);
97104
}
98-
} else {
99-
this._statuses.set(status.id, status);
100-
// It maybe the case that status hasn't changed, there isn't a good way to check this based on
101-
// `ITerminalStatus`, so just fire the event anyway.
102-
this._onDidAddStatus.fire(status);
103105
}
104106
}
105107

src/vs/workbench/contrib/terminal/test/browser/terminalStatusList.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ suite('Workbench - TerminalStatusList', () => {
130130
strictEqual(list.statuses[1].icon!.id, Codicon.zap.id, 'zap~spin should have animation removed only');
131131
});
132132

133+
test('add should fire onDidRemoveStatus if same status id with a different object reference was added', () => {
134+
const eventCalls: string[] = [];
135+
list.onDidAddStatus(() => eventCalls.push('add'));
136+
list.onDidRemoveStatus(() => eventCalls.push('remove'));
137+
list.add({ id: 'test', severity: Severity.Info });
138+
list.add({ id: 'test', severity: Severity.Info });
139+
deepStrictEqual(eventCalls, [
140+
'add',
141+
'remove',
142+
'add'
143+
]);
144+
});
145+
133146
test('remove', () => {
134147
list.add({ id: 'info', severity: Severity.Info });
135148
list.add({ id: 'warning', severity: Severity.Warning });

0 commit comments

Comments
 (0)