Skip to content

Commit

Permalink
fix: track empty editor content widget visibility in contrib (microso…
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl committed Dec 2, 2023
1 parent c8ba610 commit fda96c2
Showing 1 changed file with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export class EmptyTextEditorHintContribution implements IEditorContribution {
this.toDispose = [];
this.toDispose.push(this.editor.onDidChangeModel(() => this.update()));
this.toDispose.push(this.editor.onDidChangeModelLanguage(() => this.update()));
this.toDispose.push(this.editor.onDidChangeModelContent(() => this.update()));
this.toDispose.push(this.inlineChatService.onDidChangeProviders(() => this.update()));
this.toDispose.push(this.editor.onDidChangeModelDecorations(() => this.update()));
this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(emptyTextEditorHintSetting)) {
Expand Down Expand Up @@ -122,15 +124,28 @@ export class EmptyTextEditorHintContribution implements IEditorContribution {
return false;
}

if (this.editor.getModel()?.getValueLength()) {
return false;
}

const hasConflictingDecorations = Boolean(this.editor.getLineDecorations(1)?.find((d) =>
d.options.beforeContentClassName
|| d.options.afterContentClassName
|| d.options.before?.content
|| d.options.after?.content
));
if (hasConflictingDecorations) {
return false;
}

const inlineChatProviders = [...this.inlineChatService.getAllProvider()];
const shouldRenderDefaultHint = model?.uri.scheme === Schemas.untitled && languageId === PLAINTEXT_LANGUAGE_ID && !inlineChatProviders.length;
return inlineChatProviders.length > 0 || shouldRenderDefaultHint;
}

protected update(): void {
this.textHintContentWidget?.dispose();

if (this._shouldRenderHint()) {
const shouldRenderHint = this._shouldRenderHint();
if (shouldRenderHint && !this.textHintContentWidget) {
this.textHintContentWidget = new EmptyTextEditorHintContentWidget(
this.editor,
this._getOptions(),
Expand All @@ -142,6 +157,9 @@ export class EmptyTextEditorHintContribution implements IEditorContribution {
this.telemetryService,
this.productService
);
} else if (!shouldRenderHint && this.textHintContentWidget) {
this.textHintContentWidget.dispose();
this.textHintContentWidget = undefined;
}
}

Expand Down Expand Up @@ -172,8 +190,6 @@ class EmptyTextEditorHintContentWidget implements IContentWidget {
private readonly productService: IProductService
) {
this.toDispose = new DisposableStore();
this.toDispose.add(this.inlineChatService.onDidChangeProviders(() => this.onDidChangeModelContent()));
this.toDispose.add(this.editor.onDidChangeModelContent(() => this.onDidChangeModelContent()));
this.toDispose.add(this.editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => {
if (this.domNode && e.hasChanged(EditorOption.fontInfo)) {
this.editor.applyFontInfo(this.domNode);
Expand All @@ -185,28 +201,7 @@ class EmptyTextEditorHintContentWidget implements IContentWidget {
status(this.ariaLabel);
}
}));
this.onDidChangeModelContent();
}

private onDidChangeModelContent(): void {
if (!this.editor.getModel()?.getValueLength() && !this.hasConflictingDecorations()) {
this.editor.addContentWidget(this);
this.isVisible = true;
} else {
this.editor.removeContentWidget(this);
this.isVisible = false;
}
}

private hasConflictingDecorations(): boolean {
const res = Boolean(this.editor.getLineDecorations(1)?.find((d) =>
d.options.beforeContentClassName
|| d.options.afterContentClassName
|| d.options.before?.content
|| d.options.after?.content
));

return res;
this.editor.addContentWidget(this);
}

getId(): string {
Expand Down

0 comments on commit fda96c2

Please sign in to comment.