Skip to content

Commit 641467d

Browse files
committed
Replace editor.hover.below with editor.hover.above and have rendering below be the new default (microsoft#30797)
1 parent 5b805e4 commit 641467d

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

src/vs/editor/common/config/editorOptions.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,10 +1777,10 @@ export interface IEditorHoverOptions {
17771777
*/
17781778
sticky?: boolean;
17791779
/**
1780-
* Should the hover be shown below the line if possible?
1780+
* Should the hover be shown above the line if possible?
17811781
* Defaults to false.
17821782
*/
1783-
below?: boolean;
1783+
above?: boolean;
17841784
}
17851785

17861786
/**
@@ -1795,7 +1795,7 @@ class EditorHover extends BaseEditorOption<EditorOption.hover, EditorHoverOption
17951795
enabled: true,
17961796
delay: 300,
17971797
sticky: true,
1798-
below: false,
1798+
above: false,
17991799
};
18001800
super(
18011801
EditorOption.hover, 'hover', defaults,
@@ -1815,10 +1815,10 @@ class EditorHover extends BaseEditorOption<EditorOption.hover, EditorHoverOption
18151815
default: defaults.sticky,
18161816
description: nls.localize('hover.sticky', "Controls whether the hover should remain visible when mouse is moved over it.")
18171817
},
1818-
'editor.hover.below': {
1818+
'editor.hover.above': {
18191819
type: 'boolean',
1820-
default: defaults.below,
1821-
description: nls.localize('hover.below', "Show hovers below the line instead of above, if there's space.")
1820+
default: defaults.above,
1821+
description: nls.localize('hover.above', "Prefer showing hovers above the line, if there's space.")
18221822
},
18231823
}
18241824
);
@@ -1833,7 +1833,7 @@ class EditorHover extends BaseEditorOption<EditorOption.hover, EditorHoverOption
18331833
enabled: boolean(input.enabled, this.defaultValue.enabled),
18341834
delay: EditorIntOption.clampedInt(input.delay, this.defaultValue.delay, 0, 10000),
18351835
sticky: boolean(input.sticky, this.defaultValue.sticky),
1836-
below: boolean(input.below, this.defaultValue.below),
1836+
above: boolean(input.above, this.defaultValue.above),
18371837
};
18381838
}
18391839
}

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ import { HoverAnchor, HoverAnchorType, HoverRangeAnchor, IEditorHover, IEditorHo
2727
import { MarkdownHoverParticipant } from 'vs/editor/contrib/hover/markdownHoverParticipant';
2828
import { MarkerHoverParticipant } from 'vs/editor/contrib/hover/markerHoverParticipant';
2929
import { InlineCompletionsHoverParticipant } from 'vs/editor/contrib/inlineCompletions/inlineCompletionsHoverParticipant';
30-
import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
30+
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
3131
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
3232
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
33+
import { Context as SuggestContext } from 'vs/editor/contrib/suggest/suggest';
3334

3435
const $ = dom.$;
3536

@@ -199,13 +200,14 @@ export class ModesContentHoverWidget extends Widget implements IContentWidget, I
199200
private _shouldFocus: boolean;
200201
private _colorPicker: ColorPickerWidget | null;
201202
private _renderDisposable: IDisposable | null;
202-
private _preferBelow: boolean;
203+
private _preferAbove: boolean;
203204

204205
constructor(
205206
editor: ICodeEditor,
206207
private readonly _hoverVisibleKey: IContextKey<boolean>,
207208
@IInstantiationService instantiationService: IInstantiationService,
208209
@IKeybindingService private readonly _keybindingService: IKeybindingService,
210+
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
209211
) {
210212
super();
211213

@@ -251,7 +253,7 @@ export class ModesContentHoverWidget extends Widget implements IContentWidget, I
251253
this._isChangingDecorations = false;
252254
this._shouldFocus = false;
253255
this._colorPicker = null;
254-
this._preferBelow = this._editor.getOption(EditorOption.hover).below;
256+
this._preferAbove = this._editor.getOption(EditorOption.hover).above;
255257

256258
this._hoverOperation = new HoverOperation(
257259
this._computer,
@@ -271,7 +273,7 @@ export class ModesContentHoverWidget extends Widget implements IContentWidget, I
271273
}));
272274
this._register(editor.onDidChangeConfiguration(() => {
273275
this._hoverOperation.setHoverTime(this._editor.getOption(EditorOption.hover).delay);
274-
this._preferBelow = this._editor.getOption(EditorOption.hover).below;
276+
this._preferAbove = this._editor.getOption(EditorOption.hover).above;
275277
}));
276278
this._register(TokenizationRegistry.onDidChange(() => {
277279
if (this._isVisible && this._lastAnchor && this._messages.length > 0) {
@@ -368,15 +370,20 @@ export class ModesContentHoverWidget extends Widget implements IContentWidget, I
368370

369371
public getPosition(): IContentWidgetPosition | null {
370372
if (this._isVisible) {
373+
let preferAbove = this._preferAbove;
374+
if (!preferAbove && this._contextKeyService.getContextKeyValue<boolean>(SuggestContext.Visible.key)) {
375+
// Prefer rendering above if the suggest widget is visible
376+
preferAbove = true;
377+
}
371378
return {
372379
position: this._showAtPosition,
373380
range: this._showAtRange,
374-
preference: this._preferBelow ? [
375-
ContentWidgetPositionPreference.BELOW,
381+
preference: preferAbove ? [
376382
ContentWidgetPositionPreference.ABOVE,
383+
ContentWidgetPositionPreference.BELOW,
377384
] : [
378-
ContentWidgetPositionPreference.ABOVE,
379385
ContentWidgetPositionPreference.BELOW,
386+
ContentWidgetPositionPreference.ABOVE,
380387
],
381388
};
382389
}

src/vs/monaco.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3511,10 +3511,10 @@ declare namespace monaco.editor {
35113511
*/
35123512
sticky?: boolean;
35133513
/**
3514-
* Should the hover be shown below the line if possible?
3514+
* Should the hover be shown above the line if possible?
35153515
* Defaults to false.
35163516
*/
3517-
below?: boolean;
3517+
above?: boolean;
35183518
}
35193519

35203520
/**

0 commit comments

Comments
 (0)