Skip to content

Commit ee601d1

Browse files
TimmmmTim Hutt
authored andcommitted
Add setting to control hover position
This adds a hover setting to control whether the user wants hovers to appear above or below the relevant line, if there's space. Fixes microsoft#78560
1 parent 37ebadd commit ee601d1

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,11 @@ export interface IEditorHoverOptions {
17531753
* Defaults to true.
17541754
*/
17551755
sticky?: boolean;
1756+
/**
1757+
* Should the hover be shown below the line if possible?
1758+
* Defaults to false.
1759+
*/
1760+
below?: boolean;
17561761
}
17571762

17581763
export type EditorHoverOptions = Readonly<Required<IEditorHoverOptions>>;
@@ -1763,7 +1768,8 @@ class EditorHover extends BaseEditorOption<EditorOption.hover, EditorHoverOption
17631768
const defaults: EditorHoverOptions = {
17641769
enabled: true,
17651770
delay: 300,
1766-
sticky: true
1771+
sticky: true,
1772+
below: false,
17671773
};
17681774
super(
17691775
EditorOption.hover, 'hover', defaults,
@@ -1783,6 +1789,11 @@ class EditorHover extends BaseEditorOption<EditorOption.hover, EditorHoverOption
17831789
default: defaults.sticky,
17841790
description: nls.localize('hover.sticky', "Controls whether the hover should remain visible when mouse is moved over it.")
17851791
},
1792+
'editor.hover.below': {
1793+
type: 'boolean',
1794+
default: defaults.below,
1795+
description: nls.localize('hover.below', "Show hovers below the line instead of above, if there's space.")
1796+
},
17861797
}
17871798
);
17881799
}
@@ -1795,7 +1806,8 @@ class EditorHover extends BaseEditorOption<EditorOption.hover, EditorHoverOption
17951806
return {
17961807
enabled: boolean(input.enabled, this.defaultValue.enabled),
17971808
delay: EditorIntOption.clampedInt(input.delay, this.defaultValue.delay, 0, 10000),
1798-
sticky: boolean(input.sticky, this.defaultValue.sticky)
1809+
sticky: boolean(input.sticky, this.defaultValue.sticky),
1810+
below: boolean(input.below, this.defaultValue.below),
17991811
};
18001812
}
18011813
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ export class ModesContentHoverWidget extends Widget implements IContentWidget, I
202202
private _shouldFocus: boolean;
203203
private _colorPicker: ColorPickerWidget | null;
204204
private _renderDisposable: IDisposable | null;
205+
private _preferBelow: boolean;
205206

206207
constructor(
207208
editor: ICodeEditor,
@@ -252,6 +253,7 @@ export class ModesContentHoverWidget extends Widget implements IContentWidget, I
252253
this._isChangingDecorations = false;
253254
this._shouldFocus = false;
254255
this._colorPicker = null;
256+
this._preferBelow = this._editor.getOption(EditorOption.hover).below;
255257

256258
this._hoverOperation = new HoverOperation(
257259
this._computer,
@@ -271,6 +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);
276+
this._preferBelow = this._editor.getOption(EditorOption.hover).below;
274277
}));
275278
this._register(TokenizationRegistry.onDidChange(() => {
276279
if (this._isVisible && this._lastAnchor && this._messages.length > 0) {
@@ -370,10 +373,13 @@ export class ModesContentHoverWidget extends Widget implements IContentWidget, I
370373
return {
371374
position: this._showAtPosition,
372375
range: this._showAtRange,
373-
preference: [
376+
preference: this._preferBelow ? [
377+
ContentWidgetPositionPreference.BELOW,
374378
ContentWidgetPositionPreference.ABOVE,
375-
ContentWidgetPositionPreference.BELOW
376-
]
379+
] : [
380+
ContentWidgetPositionPreference.ABOVE,
381+
ContentWidgetPositionPreference.BELOW,
382+
],
377383
};
378384
}
379385
return null;

src/vs/monaco.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3485,6 +3485,11 @@ declare namespace monaco.editor {
34853485
* Defaults to true.
34863486
*/
34873487
sticky?: boolean;
3488+
/**
3489+
* Should the hover be shown below the line if possible?
3490+
* Defaults to false.
3491+
*/
3492+
below?: boolean;
34883493
}
34893494

34903495
export type EditorHoverOptions = Readonly<Required<IEditorHoverOptions>>;

0 commit comments

Comments
 (0)