Skip to content

Commit 9e7cd44

Browse files
authored
fix: show context menu option to disable empty editor hint (microsoft#218548)
* fix: show context menu option to disable empty editor hint * Fix action name
1 parent b9f2435 commit 9e7cd44

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import { SEARCH_RESULT_LANGUAGE_ID } from 'vs/workbench/services/search/common/s
3434
import { getDefaultHoverDelegate } from 'vs/base/browser/ui/hover/hoverDelegateFactory';
3535
import { IHoverService } from 'vs/platform/hover/browser/hover';
3636
import { ChatAgentLocation, IChatAgent, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
37+
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
38+
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
3739

3840
const $ = dom.$;
3941

@@ -60,6 +62,7 @@ export class EmptyTextEditorHintContribution implements IEditorContribution {
6062
@IChatAgentService private readonly chatAgentService: IChatAgentService,
6163
@ITelemetryService private readonly telemetryService: ITelemetryService,
6264
@IProductService protected readonly productService: IProductService,
65+
@IContextMenuService private readonly contextMenuService: IContextMenuService
6366
) {
6467
this.toDispose = [];
6568
this.toDispose.push(this.editor.onDidChangeModel(() => this.update()));
@@ -145,7 +148,8 @@ export class EmptyTextEditorHintContribution implements IEditorContribution {
145148
this.keybindingService,
146149
this.chatAgentService,
147150
this.telemetryService,
148-
this.productService
151+
this.productService,
152+
this.contextMenuService
149153
);
150154
} else if (!shouldRenderHint && this.textHintContentWidget) {
151155
this.textHintContentWidget.dispose();
@@ -178,7 +182,8 @@ class EmptyTextEditorHintContentWidget implements IContentWidget {
178182
private readonly keybindingService: IKeybindingService,
179183
private readonly chatAgentService: IChatAgentService,
180184
private readonly telemetryService: ITelemetryService,
181-
private readonly productService: IProductService
185+
private readonly productService: IProductService,
186+
private readonly contextMenuService: IContextMenuService,
182187
) {
183188
this.toDispose = new DisposableStore();
184189
this.toDispose.add(this.editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => {
@@ -199,10 +204,34 @@ class EmptyTextEditorHintContentWidget implements IContentWidget {
199204
return EmptyTextEditorHintContentWidget.ID;
200205
}
201206

202-
private _disableHint() {
203-
this.configurationService.updateValue(emptyTextEditorHintSetting, 'hidden');
204-
this.dispose();
205-
this.editor.focus();
207+
private _disableHint(e?: MouseEvent) {
208+
const disableHint = () => {
209+
this.configurationService.updateValue(emptyTextEditorHintSetting, 'hidden');
210+
this.dispose();
211+
this.editor.focus();
212+
};
213+
214+
if (!e) {
215+
disableHint();
216+
return;
217+
}
218+
219+
this.contextMenuService.showContextMenu({
220+
getAnchor: () => { return new StandardMouseEvent(dom.getActiveWindow(), e); },
221+
getActions: () => {
222+
return [{
223+
id: 'workench.action.disableEmptyEditorHint',
224+
label: localize('disableEditorEmptyHint', "Disable Empty Editor Hint"),
225+
tooltip: localize('disableEditorEmptyHint', "Disable Empty Editor Hint"),
226+
enabled: true,
227+
class: undefined,
228+
run: () => {
229+
disableHint();
230+
}
231+
}
232+
];
233+
}
234+
});
206235
}
207236

208237
private _getHintInlineChat(providers: IChatAgent[]) {
@@ -244,7 +273,7 @@ class EmptyTextEditorHintContentWidget implements IContentWidget {
244273
const hintPart = $('a', undefined, fragment);
245274
hintPart.style.fontStyle = 'italic';
246275
hintPart.style.cursor = 'pointer';
247-
this.toDispose.add(dom.addDisposableListener(hintPart, dom.EventType.CONTEXT_MENU, () => this._disableHint()));
276+
this.toDispose.add(dom.addDisposableListener(hintPart, dom.EventType.CONTEXT_MENU, (e) => this._disableHint(e)));
248277
this.toDispose.add(dom.addDisposableListener(hintPart, dom.EventType.CLICK, handleClick));
249278
return hintPart;
250279
} else {
@@ -263,7 +292,7 @@ class EmptyTextEditorHintContentWidget implements IContentWidget {
263292

264293
if (this.options.clickable) {
265294
label.element.style.cursor = 'pointer';
266-
this.toDispose.add(dom.addDisposableListener(label.element, dom.EventType.CONTEXT_MENU, () => this._disableHint()));
295+
this.toDispose.add(dom.addDisposableListener(label.element, dom.EventType.CONTEXT_MENU, (e) => this._disableHint(e)));
267296
this.toDispose.add(dom.addDisposableListener(label.element, dom.EventType.CLICK, handleClick));
268297
}
269298

src/vs/workbench/contrib/notebook/browser/contrib/editorHint/emptyCellEditorHint.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
88
import { EditorContributionInstantiation, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
99
import { ICommandService } from 'vs/platform/commands/common/commands';
1010
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
11+
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1112
import { IHoverService } from 'vs/platform/hover/browser/hover';
1213
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1314
import { IProductService } from 'vs/platform/product/common/productService';
@@ -32,7 +33,8 @@ export class EmptyCellEditorHintContribution extends EmptyTextEditorHintContribu
3233
@IInlineChatSessionService inlineChatSessionService: IInlineChatSessionService,
3334
@IChatAgentService chatAgentService: IChatAgentService,
3435
@ITelemetryService telemetryService: ITelemetryService,
35-
@IProductService productService: IProductService
36+
@IProductService productService: IProductService,
37+
@IContextMenuService contextMenuService: IContextMenuService
3638
) {
3739
super(
3840
editor,
@@ -44,7 +46,8 @@ export class EmptyCellEditorHintContribution extends EmptyTextEditorHintContribu
4446
inlineChatSessionService,
4547
chatAgentService,
4648
telemetryService,
47-
productService
49+
productService,
50+
contextMenuService
4851
);
4952

5053
const activeEditor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);

0 commit comments

Comments
 (0)