Skip to content

Commit 8f9f5cc

Browse files
committed
Improve hover positioning by introducing a secondary anchor
1 parent 78fffb9 commit 8f9f5cc

File tree

5 files changed

+133
-142
lines changed

5 files changed

+133
-142
lines changed

src/vs/editor/browser/editorBrowser.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,11 @@ export interface IContentWidgetPosition {
132132
*/
133133
position: IPosition | null;
134134
/**
135-
* Optionally, a range can be provided to further
136-
* define the position of the content widget.
135+
* Optionally, a secondary position can be provided to further
136+
* define the position of the content widget. The secondary position
137+
* must have the same line number as the primary position.
137138
*/
138-
range?: IRange | null;
139+
secondaryPosition?: IPosition | null;
139140
/**
140141
* Placement preference for position, in order of preference.
141142
*/

src/vs/editor/browser/view.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import { SelectionsOverlay } from 'vs/editor/browser/viewParts/selections/select
3737
import { ViewCursors } from 'vs/editor/browser/viewParts/viewCursors/viewCursors';
3838
import { ViewZones } from 'vs/editor/browser/viewParts/viewZones/viewZones';
3939
import { Position } from 'vs/editor/common/core/position';
40-
import { Range } from 'vs/editor/common/core/range';
4140
import { ScrollType } from 'vs/editor/common/editorCommon';
4241
import { IEditorConfiguration } from 'vs/editor/common/config/editorConfiguration';
4342
import { RenderingContext } from 'vs/editor/browser/view/renderingContext';
@@ -502,15 +501,13 @@ export class View extends ViewEventHandler {
502501
}
503502

504503
public layoutContentWidget(widgetData: IContentWidgetData): void {
505-
let newRange = widgetData.position ? widgetData.position.range || null : null;
506-
if (newRange === null) {
507-
const newPosition = widgetData.position ? widgetData.position.position : null;
508-
if (newPosition !== null) {
509-
newRange = new Range(newPosition.lineNumber, newPosition.column, newPosition.lineNumber, newPosition.column);
510-
}
511-
}
512-
const newPreference = widgetData.position ? widgetData.position.preference : null;
513-
this._contentWidgets.setWidgetPosition(widgetData.widget, newRange, newPreference, widgetData.position?.positionAffinity ?? null);
504+
this._contentWidgets.setWidgetPosition(
505+
widgetData.widget,
506+
widgetData.position?.position ?? null,
507+
widgetData.position?.secondaryPosition ?? null,
508+
widgetData.position?.preference ?? null,
509+
widgetData.position?.positionAffinity ?? null
510+
);
514511
this._scheduleRender();
515512
}
516513

0 commit comments

Comments
 (0)