Skip to content

Commit

Permalink
Merge pull request #163970 from microsoft/alexd/convinced-wildebeest
Browse files Browse the repository at this point in the history
Improve hover positioning
  • Loading branch information
alexdima committed Oct 18, 2022
2 parents 3bfd385 + b69147f commit 2798da9
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 158 deletions.
7 changes: 4 additions & 3 deletions src/vs/editor/browser/editorBrowser.ts
Expand Up @@ -132,10 +132,11 @@ export interface IContentWidgetPosition {
*/
position: IPosition | null;
/**
* Optionally, a range can be provided to further
* define the position of the content widget.
* Optionally, a secondary position can be provided to further
* define the position of the content widget. The secondary position
* must have the same line number as the primary position.
*/
range?: IRange | null;
secondaryPosition?: IPosition | null;
/**
* Placement preference for position, in order of preference.
*/
Expand Down
17 changes: 7 additions & 10 deletions src/vs/editor/browser/view.ts
Expand Up @@ -37,7 +37,6 @@ import { SelectionsOverlay } from 'vs/editor/browser/viewParts/selections/select
import { ViewCursors } from 'vs/editor/browser/viewParts/viewCursors/viewCursors';
import { ViewZones } from 'vs/editor/browser/viewParts/viewZones/viewZones';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { ScrollType } from 'vs/editor/common/editorCommon';
import { IEditorConfiguration } from 'vs/editor/common/config/editorConfiguration';
import { RenderingContext } from 'vs/editor/browser/view/renderingContext';
Expand Down Expand Up @@ -502,15 +501,13 @@ export class View extends ViewEventHandler {
}

public layoutContentWidget(widgetData: IContentWidgetData): void {
let newRange = widgetData.position ? widgetData.position.range || null : null;
if (newRange === null) {
const newPosition = widgetData.position ? widgetData.position.position : null;
if (newPosition !== null) {
newRange = new Range(newPosition.lineNumber, newPosition.column, newPosition.lineNumber, newPosition.column);
}
}
const newPreference = widgetData.position ? widgetData.position.preference : null;
this._contentWidgets.setWidgetPosition(widgetData.widget, newRange, newPreference, widgetData.position?.positionAffinity ?? null);
this._contentWidgets.setWidgetPosition(
widgetData.widget,
widgetData.position?.position ?? null,
widgetData.position?.secondaryPosition ?? null,
widgetData.position?.preference ?? null,
widgetData.position?.positionAffinity ?? null
);
this._scheduleRender();
}

Expand Down
32 changes: 32 additions & 0 deletions src/vs/editor/browser/view/renderingContext.ts
Expand Up @@ -87,6 +87,38 @@ export class RenderingContext extends RestrictedRenderingContext {
}

export class LineVisibleRanges {
/**
* Returns the element with the smallest `lineNumber`.
*/
public static firstLine(ranges: LineVisibleRanges[] | null): LineVisibleRanges | null {
if (!ranges) {
return null;
}
let result: LineVisibleRanges | null = null;
for (const range of ranges) {
if (!result || range.lineNumber < result.lineNumber) {
result = range;
}
}
return result;
}

/**
* Returns the element with the largest `lineNumber`.
*/
public static lastLine(ranges: LineVisibleRanges[] | null): LineVisibleRanges | null {
if (!ranges) {
return null;
}
let result: LineVisibleRanges | null = null;
for (const range of ranges) {
if (!result || range.lineNumber > result.lineNumber) {
result = range;
}
}
return result;
}

constructor(
public readonly outsideRenderedLine: boolean,
public readonly lineNumber: number,
Expand Down

0 comments on commit 2798da9

Please sign in to comment.