Skip to content

Commit 28e1298

Browse files
authored
Schedule welcome widget to show once between typing. (microsoft#183606)
* Schedule dialog to show once between typing * Don't re-render if already displayed once
1 parent 5dd48a7 commit 28e1298

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

src/vs/workbench/contrib/welcomeDialog/browser/welcomeDialog.contribution.ts

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ import { GettingStartedDetailsRenderer } from 'vs/workbench/contrib/welcomeGetti
2727
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
2828
import { localize } from 'vs/nls';
2929
import { applicationConfigurationNodeBase } from 'vs/workbench/common/configuration';
30+
import { RunOnceScheduler } from 'vs/base/common/async';
3031

3132
const configurationKey = 'workbench.welcome.experimental.dialog';
3233

3334
class WelcomeDialogContribution extends Disposable implements IWorkbenchContribution {
3435

3536
private contextKeysToWatch = new Set<string>();
37+
private isRendered = false;
3638

3739
constructor(
3840
@IStorageService storageService: IStorageService,
@@ -69,27 +71,41 @@ class WelcomeDialogContribution extends Disposable implements IWorkbenchContribu
6971
this.contextKeysToWatch.add(welcomeDialog.when);
7072

7173
this._register(this.contextService.onDidChangeContext(e => {
72-
if (e.affectsSome(this.contextKeysToWatch) &&
73-
Array.from(this.contextKeysToWatch).every(value => this.contextService.contextMatchesRules(ContextKeyExpr.deserialize(value)))) {
74-
const codeEditor = this.codeEditorService.getActiveCodeEditor();
75-
if (codeEditor?.hasModel()) {
74+
if (e.affectsSome(this.contextKeysToWatch) && !this.isRendered) {
7675

77-
const detailsRenderer = new GettingStartedDetailsRenderer(fileService, notificationService, extensionService, languageService);
76+
if (!Array.from(this.contextKeysToWatch).every(value => this.contextService.contextMatchesRules(ContextKeyExpr.deserialize(value)))) {
77+
return;
78+
}
7879

79-
const welcomeWidget = new WelcomeWidget(
80-
codeEditor,
81-
instantiationService,
82-
commandService,
83-
telemetryService,
84-
openerService,
85-
webviewService,
86-
detailsRenderer);
80+
const codeEditor = this.codeEditorService.getActiveCodeEditor();
8781

88-
welcomeWidget.render(welcomeDialog.title,
89-
welcomeDialog.message,
90-
welcomeDialog.buttonText,
91-
welcomeDialog.buttonCommand,
92-
welcomeDialog.media);
82+
if (codeEditor?.hasModel()) {
83+
const scheduler = new RunOnceScheduler(() => {
84+
this.isRendered = true;
85+
const detailsRenderer = new GettingStartedDetailsRenderer(fileService, notificationService, extensionService, languageService);
86+
87+
const welcomeWidget = new WelcomeWidget(
88+
codeEditor,
89+
instantiationService,
90+
commandService,
91+
telemetryService,
92+
openerService,
93+
webviewService,
94+
detailsRenderer);
95+
96+
welcomeWidget.render(welcomeDialog.title,
97+
welcomeDialog.message,
98+
welcomeDialog.buttonText,
99+
welcomeDialog.buttonCommand,
100+
welcomeDialog.media);
101+
102+
}, 3000);
103+
104+
this._register(codeEditor.onDidChangeModelContent((e) => {
105+
if (!this.isRendered) {
106+
scheduler.schedule();
107+
}
108+
}));
93109

94110
this.contextKeysToWatch.delete(welcomeDialog.when);
95111
}
@@ -110,7 +126,7 @@ configurationRegistry.registerConfiguration({
110126
type: 'boolean',
111127
default: false,
112128
tags: ['experimental'],
113-
description: localize('workbench.welcome.dialog', "When enabled, a welcome widget is shown in the edior")
129+
description: localize('workbench.welcome.dialog', "When enabled, a welcome widget is shown in the editor")
114130
}
115131
}
116132
});

0 commit comments

Comments
 (0)