Skip to content

Commit 2798da9

Browse files
authored
Merge pull request microsoft#163970 from microsoft/alexd/convinced-wildebeest
Improve hover positioning
2 parents 3bfd385 + b69147f commit 2798da9

File tree

7 files changed

+168
-158
lines changed

7 files changed

+168
-158
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

src/vs/editor/browser/view/renderingContext.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,38 @@ export class RenderingContext extends RestrictedRenderingContext {
8787
}
8888

8989
export class LineVisibleRanges {
90+
/**
91+
* Returns the element with the smallest `lineNumber`.
92+
*/
93+
public static firstLine(ranges: LineVisibleRanges[] | null): LineVisibleRanges | null {
94+
if (!ranges) {
95+
return null;
96+
}
97+
let result: LineVisibleRanges | null = null;
98+
for (const range of ranges) {
99+
if (!result || range.lineNumber < result.lineNumber) {
100+
result = range;
101+
}
102+
}
103+
return result;
104+
}
105+
106+
/**
107+
* Returns the element with the largest `lineNumber`.
108+
*/
109+
public static lastLine(ranges: LineVisibleRanges[] | null): LineVisibleRanges | null {
110+
if (!ranges) {
111+
return null;
112+
}
113+
let result: LineVisibleRanges | null = null;
114+
for (const range of ranges) {
115+
if (!result || range.lineNumber > result.lineNumber) {
116+
result = range;
117+
}
118+
}
119+
return result;
120+
}
121+
90122
constructor(
91123
public readonly outsideRenderedLine: boolean,
92124
public readonly lineNumber: number,

0 commit comments

Comments
 (0)