Skip to content

Commit eff2fb7

Browse files
committed
Add editor hover context key
Fix microsoft#98971
1 parent 60a6939 commit eff2fb7

5 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/vs/editor/common/editorContextKeys.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export namespace EditorContextKeys {
3636
export const canUndo = new RawContextKey<boolean>('canUndo', false);
3737
export const canRedo = new RawContextKey<boolean>('canRedo', false);
3838

39+
export const hoverVisible = new RawContextKey<boolean>('editorHoverVisible', false);
40+
3941
/**
4042
* A context key that is set when an editor is part of a larger editor, like notebooks or
4143
* (future) a diff editor

src/vs/editor/contrib/hover/hover.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDeco
2626
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
2727
import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
2828
import { GotoDefinitionAtPositionEditorContribution } from 'vs/editor/contrib/gotoSymbol/link/goToDefinitionAtPosition';
29+
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
2930

3031
export class ModesHoverController implements IEditorContribution {
3132

@@ -56,6 +57,8 @@ export class ModesHoverController implements IEditorContribution {
5657
private _isHoverEnabled!: boolean;
5758
private _isHoverSticky!: boolean;
5859

60+
private _hoverVisibleKey: IContextKey<boolean>;
61+
5962
static get(editor: ICodeEditor): ModesHoverController {
6063
return editor.getContribution<ModesHoverController>(ModesHoverController.ID);
6164
}
@@ -65,7 +68,8 @@ export class ModesHoverController implements IEditorContribution {
6568
@IModeService private readonly _modeService: IModeService,
6669
@IMarkerDecorationsService private readonly _markerDecorationsService: IMarkerDecorationsService,
6770
@IKeybindingService private readonly _keybindingService: IKeybindingService,
68-
@IThemeService private readonly _themeService: IThemeService
71+
@IThemeService private readonly _themeService: IThemeService,
72+
@IContextKeyService _contextKeyService: IContextKeyService
6973
) {
7074
this._isMouseDown = false;
7175
this._hoverClicked = false;
@@ -79,6 +83,8 @@ export class ModesHoverController implements IEditorContribution {
7983
this._hookEvents();
8084
}
8185
});
86+
87+
this._hoverVisibleKey = EditorContextKeys.hoverVisible.bindTo(_contextKeyService);
8288
}
8389

8490
private _hookEvents(): void {
@@ -204,7 +210,7 @@ export class ModesHoverController implements IEditorContribution {
204210
}
205211

206212
private _createHoverWidgets() {
207-
this._contentWidget.value = new ModesContentHoverWidget(this._editor, this._markerDecorationsService, this._keybindingService, this._themeService, this._modeService, this._openerService);
213+
this._contentWidget.value = new ModesContentHoverWidget(this._editor, this._hoverVisibleKey, this._markerDecorationsService, this._keybindingService, this._themeService, this._modeService, this._openerService);
208214
this._glyphWidget.value = new ModesGlyphHoverWidget(this._editor, this._modeService, this._openerService);
209215
}
210216

src/vs/editor/contrib/hover/hoverWidgets.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Range } from 'vs/editor/common/core/range';
1414
import { renderHoverAction, HoverWidget } from 'vs/base/browser/ui/hover/hoverWidget';
1515
import { IDisposable } from 'vs/base/common/lifecycle';
1616
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
17+
import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
1718

1819
export class ContentHoverWidget extends Widget implements IContentWidget {
1920

@@ -40,6 +41,7 @@ export class ContentHoverWidget extends Widget implements IContentWidget {
4041
constructor(
4142
id: string,
4243
editor: ICodeEditor,
44+
private readonly _hoverVisibleKey: IContextKey<boolean>,
4345
private readonly _keybindingService: IKeybindingService
4446
) {
4547
super();
@@ -83,6 +85,7 @@ export class ContentHoverWidget extends Widget implements IContentWidget {
8385
// Position has changed
8486
this._showAtPosition = position;
8587
this._showAtRange = range;
88+
this._hoverVisibleKey.set(true);
8689
this.isVisible = true;
8790

8891
this._editor.layoutContentWidget(this);
@@ -100,6 +103,12 @@ export class ContentHoverWidget extends Widget implements IContentWidget {
100103
return;
101104
}
102105

106+
setTimeout(() => {
107+
// Give commands a chance to see the key
108+
if (!this.isVisible) {
109+
this._hoverVisibleKey.set(false);
110+
}
111+
}, 0);
103112
this.isVisible = false;
104113

105114
this._editor.layoutContentWidget(this);

src/vs/editor/contrib/hover/modesContentHover.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { EditorOption } from 'vs/editor/common/config/editorOptions';
4141
import { Constants } from 'vs/base/common/uint';
4242
import { textLinkForeground } from 'vs/platform/theme/common/colorRegistry';
4343
import { Progress } from 'vs/platform/progress/common/progress';
44+
import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
4445

4546
const $ = dom.$;
4647

@@ -212,13 +213,14 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
212213

213214
constructor(
214215
editor: ICodeEditor,
216+
_hoverVisibleKey: IContextKey<boolean>,
215217
markerDecorationsService: IMarkerDecorationsService,
216218
keybindingService: IKeybindingService,
217219
private readonly _themeService: IThemeService,
218220
private readonly _modeService: IModeService,
219221
private readonly _openerService: IOpenerService = NullOpenerService,
220222
) {
221-
super(ModesContentHoverWidget.ID, editor, keybindingService);
223+
super(ModesContentHoverWidget.ID, editor, _hoverVisibleKey, keybindingService);
222224

223225
this._messages = [];
224226
this._lastRange = null;

src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ registerAction2(class extends NotebookAction {
326326
title: localize('notebookActions.quitEditing', "Quit Notebook Cell Editing"),
327327
category: NOTEBOOK_ACTIONS_CATEGORY,
328328
keybinding: {
329-
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, InputFocusedContext),
329+
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, InputFocusedContext, EditorContextKeys.hoverVisible.toNegated()),
330330
primary: KeyCode.Escape,
331331
weight: EDITOR_WIDGET_ACTION_WEIGHT - 5
332332
},

0 commit comments

Comments
 (0)