Skip to content

Commit 426f82c

Browse files
authored
Merge pull request microsoft#127609 from Timmmm/hover_position
Add setting to control hover position
2 parents b1f406f + ee601d1 commit 426f82c

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
@@ -1776,6 +1776,11 @@ export interface IEditorHoverOptions {
17761776
* Defaults to true.
17771777
*/
17781778
sticky?: boolean;
1779+
/**
1780+
* Should the hover be shown below the line if possible?
1781+
* Defaults to false.
1782+
*/
1783+
below?: boolean;
17791784
}
17801785

17811786
/**
@@ -1789,7 +1794,8 @@ class EditorHover extends BaseEditorOption<EditorOption.hover, EditorHoverOption
17891794
const defaults: EditorHoverOptions = {
17901795
enabled: true,
17911796
delay: 300,
1792-
sticky: true
1797+
sticky: true,
1798+
below: false,
17931799
};
17941800
super(
17951801
EditorOption.hover, 'hover', defaults,
@@ -1809,6 +1815,11 @@ class EditorHover extends BaseEditorOption<EditorOption.hover, EditorHoverOption
18091815
default: defaults.sticky,
18101816
description: nls.localize('hover.sticky', "Controls whether the hover should remain visible when mouse is moved over it.")
18111817
},
1818+
'editor.hover.below': {
1819+
type: 'boolean',
1820+
default: defaults.below,
1821+
description: nls.localize('hover.below', "Show hovers below the line instead of above, if there's space.")
1822+
},
18121823
}
18131824
);
18141825
}
@@ -1821,7 +1832,8 @@ class EditorHover extends BaseEditorOption<EditorOption.hover, EditorHoverOption
18211832
return {
18221833
enabled: boolean(input.enabled, this.defaultValue.enabled),
18231834
delay: EditorIntOption.clampedInt(input.delay, this.defaultValue.delay, 0, 10000),
1824-
sticky: boolean(input.sticky, this.defaultValue.sticky)
1835+
sticky: boolean(input.sticky, this.defaultValue.sticky),
1836+
below: boolean(input.below, this.defaultValue.below),
18251837
};
18261838
}
18271839
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export class ModesContentHoverWidget extends Widget implements IContentWidget, I
199199
private _shouldFocus: boolean;
200200
private _colorPicker: ColorPickerWidget | null;
201201
private _renderDisposable: IDisposable | null;
202+
private _preferBelow: boolean;
202203

203204
constructor(
204205
editor: ICodeEditor,
@@ -250,6 +251,7 @@ export class ModesContentHoverWidget extends Widget implements IContentWidget, I
250251
this._isChangingDecorations = false;
251252
this._shouldFocus = false;
252253
this._colorPicker = null;
254+
this._preferBelow = this._editor.getOption(EditorOption.hover).below;
253255

254256
this._hoverOperation = new HoverOperation(
255257
this._computer,
@@ -269,6 +271,7 @@ export class ModesContentHoverWidget extends Widget implements IContentWidget, I
269271
}));
270272
this._register(editor.onDidChangeConfiguration(() => {
271273
this._hoverOperation.setHoverTime(this._editor.getOption(EditorOption.hover).delay);
274+
this._preferBelow = this._editor.getOption(EditorOption.hover).below;
272275
}));
273276
this._register(TokenizationRegistry.onDidChange(() => {
274277
if (this._isVisible && this._lastAnchor && this._messages.length > 0) {
@@ -368,10 +371,13 @@ export class ModesContentHoverWidget extends Widget implements IContentWidget, I
368371
return {
369372
position: this._showAtPosition,
370373
range: this._showAtRange,
371-
preference: [
374+
preference: this._preferBelow ? [
375+
ContentWidgetPositionPreference.BELOW,
372376
ContentWidgetPositionPreference.ABOVE,
373-
ContentWidgetPositionPreference.BELOW
374-
]
377+
] : [
378+
ContentWidgetPositionPreference.ABOVE,
379+
ContentWidgetPositionPreference.BELOW,
380+
],
375381
};
376382
}
377383
return null;

src/vs/monaco.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3510,6 +3510,11 @@ declare namespace monaco.editor {
35103510
* Defaults to true.
35113511
*/
35123512
sticky?: boolean;
3513+
/**
3514+
* Should the hover be shown below the line if possible?
3515+
* Defaults to false.
3516+
*/
3517+
below?: boolean;
35133518
}
35143519

35153520
/**

0 commit comments

Comments
 (0)