Skip to content

Commit f8cc13b

Browse files
committed
Improve case where active instance already exists
1 parent 11308ef commit f8cc13b

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/vs/workbench/contrib/terminalContrib/history/browser/terminal.history.contribution.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { KeyCode, KeyMod } from '../../../../../base/common/keyCodes.js';
7-
import { Disposable } from '../../../../../base/common/lifecycle.js';
7+
import { Disposable, DisposableStore } from '../../../../../base/common/lifecycle.js';
88
import { localize2 } from '../../../../../nls.js';
99
import { AccessibleViewProviderId } from '../../../../../platform/accessibility/browser/accessibleView.js';
1010
import { CONTEXT_ACCESSIBILITY_MODE_ENABLED } from '../../../../../platform/accessibility/common/accessibility.js';
@@ -147,21 +147,17 @@ registerTerminalAction({
147147
}
148148
],
149149
run: async (c, accessor) => {
150-
// If there are no active instances, then create a new terminal instance
151-
const activeInstance = await c.service.getActiveOrCreateInstance();
152-
// Newly created instances will not have a shell type set yet
153-
// This will result in the command picker not showing up, so wait for it to be set
154-
if (!activeInstance.shellType) {
150+
let activeInstance = c.service.activeInstance;
151+
// If an instanec doesn't exist, create one and wait for shell type to be set
152+
if (!activeInstance) {
153+
const newInstance = activeInstance = await c.service.getActiveOrCreateInstance();
155154
await c.service.revealActiveTerminal();
156-
const wasDisposedPrematurely = await new Promise<boolean>(resolve => {
157-
activeInstance.onDidChangeShellType(() => {
158-
resolve(false);
159-
});
160-
activeInstance.onDisposed(() => {
161-
resolve(true);
162-
});
155+
const store = new DisposableStore();
156+
const wasDisposedPrematurely = await new Promise<boolean>(r => {
157+
store.add(newInstance.onDidChangeShellType(() => r(false)));
158+
store.add(newInstance.onDisposed(() => r(true)));
163159
});
164-
// If the instance was disposed before the shell type was set, then exit
160+
store.dispose();
165161
if (wasDisposedPrematurely) {
166162
return;
167163
}

0 commit comments

Comments
 (0)