From 88e857430c5be0f9ff764c2a499fc67ceac9f11d Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Wed, 6 Dec 2023 13:43:10 +0100 Subject: [PATCH 1/2] refactoring the content hover ts file --- .../contrib/hover/browser/contentHover.ts | 305 +++++++++++------- src/vs/editor/contrib/hover/browser/hover.ts | 16 +- .../hover/test/browser/contentHover.test.ts | 6 +- 3 files changed, 192 insertions(+), 135 deletions(-) diff --git a/src/vs/editor/contrib/hover/browser/contentHover.ts b/src/vs/editor/contrib/hover/browser/contentHover.ts index c361be19543..f5630ea7fc2 100644 --- a/src/vs/editor/contrib/hover/browser/contentHover.ts +++ b/src/vs/editor/contrib/hover/browser/contentHover.ts @@ -29,25 +29,15 @@ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessib const $ = dom.$; -export class ContentHoverController extends Disposable { - - private readonly _participants: IEditorHoverParticipant[]; - - private readonly _widget: ContentHoverWidget; - - getWidgetContent(): string | undefined { - const node = this._widget.getDomNode(); - if (!node.textContent) { - return undefined; - } - return node.textContent; - } - - private readonly _computer: ContentHoverComputer; - private readonly _hoverOperation: HoverOperation; +export class ContentHoverWidget extends Disposable { private _currentResult: HoverResult | null = null; + private readonly _computer: ContentHoverComputer; + private readonly _widget: ResizableContentHoverWidget; + private readonly _participants: IEditorHoverParticipant[]; + private readonly _hoverOperation: HoverOperation; + constructor( private readonly _editor: ICodeEditor, @IInstantiationService private readonly _instantiationService: IInstantiationService, @@ -55,7 +45,7 @@ export class ContentHoverController extends Disposable { ) { super(); - this._widget = this._register(this._instantiationService.createInstance(ContentHoverWidget, this._editor)); + this._widget = this._register(this._instantiationService.createInstance(ResizableContentHoverWidget, this._editor)); // Instantiate participants and sort them by `hoverOrdinal` which is relevant for rendering order. this._participants = []; @@ -87,58 +77,17 @@ export class ContentHoverController extends Disposable { })); } - get widget() { - return this._widget; - } - /** * Returns true if the hover shows now or will show. */ - public maybeShowAt(mouseEvent: IEditorMouseEvent): boolean { - if (this._widget.isResizing) { - return true; - } - const anchorCandidates: HoverAnchor[] = []; + private _startShowingOrUpdateHover( + anchor: HoverAnchor | null, + mode: HoverStartMode, + source: HoverStartSource, + focus: boolean, + mouseEvent: IEditorMouseEvent | null + ): boolean { - for (const participant of this._participants) { - if (participant.suggestHoverAnchor) { - const anchor = participant.suggestHoverAnchor(mouseEvent); - if (anchor) { - anchorCandidates.push(anchor); - } - } - } - - const target = mouseEvent.target; - - if (target.type === MouseTargetType.CONTENT_TEXT) { - anchorCandidates.push(new HoverRangeAnchor(0, target.range, mouseEvent.event.posx, mouseEvent.event.posy)); - } - - if (target.type === MouseTargetType.CONTENT_EMPTY) { - const epsilon = this._editor.getOption(EditorOption.fontInfo).typicalHalfwidthCharacterWidth / 2; - if (!target.detail.isAfterLines && typeof target.detail.horizontalDistanceToText === 'number' && target.detail.horizontalDistanceToText < epsilon) { - // Let hover kick in even when the mouse is technically in the empty area after a line, given the distance is small enough - anchorCandidates.push(new HoverRangeAnchor(0, target.range, mouseEvent.event.posx, mouseEvent.event.posy)); - } - } - - if (anchorCandidates.length === 0) { - return this._startShowingOrUpdateHover(null, HoverStartMode.Delayed, HoverStartSource.Mouse, false, mouseEvent); - } - - anchorCandidates.sort((a, b) => b.priority - a.priority); - return this._startShowingOrUpdateHover(anchorCandidates[0], HoverStartMode.Delayed, HoverStartSource.Mouse, false, mouseEvent); - } - - public startShowingAtRange(range: Range, mode: HoverStartMode, source: HoverStartSource, focus: boolean): void { - this._startShowingOrUpdateHover(new HoverRangeAnchor(0, range, undefined, undefined), mode, source, focus, null); - } - - /** - * Returns true if the hover shows now or will show. - */ - private _startShowingOrUpdateHover(anchor: HoverAnchor | null, mode: HoverStartMode, source: HoverStartSource, focus: boolean, mouseEvent: IEditorMouseEvent | null): boolean { if (!this._widget.position || !this._currentResult) { // The hover is not visible if (anchor) { @@ -149,8 +98,13 @@ export class ContentHoverController extends Disposable { } // The hover is currently visible - const hoverIsSticky = this._editor.getOption(EditorOption.hover).sticky; - const isGettingCloser = (hoverIsSticky && mouseEvent && this._widget.isMouseGettingCloser(mouseEvent.event.posx, mouseEvent.event.posy)); + const isHoverSticky = this._editor.getOption(EditorOption.hover).sticky; + const isGettingCloser = ( + isHoverSticky + && mouseEvent + && this._widget.isMouseGettingCloser(mouseEvent.event.posx, mouseEvent.event.posy) + ); + if (isGettingCloser) { // The mouse is getting closer to the hover, so we will keep the hover untouched // But we will kick off a hover update at the new anchor, insisting on keeping the hover visible. @@ -185,11 +139,11 @@ export class ContentHoverController extends Disposable { } private _startHoverOperationIfNecessary(anchor: HoverAnchor, mode: HoverStartMode, source: HoverStartSource, focus: boolean, insistOnKeepingHoverVisible: boolean): void { + if (this._computer.anchor && this._computer.anchor.equals(anchor)) { // We have to start a hover operation at the exact same anchor as before, so no work is needed return; } - this._hoverOperation.cancel(); this._computer.anchor = anchor; this._computer.shouldFocus = focus; @@ -199,6 +153,7 @@ export class ContentHoverController extends Disposable { } private _setCurrentResult(hoverResult: HoverResult | null): void { + if (this._currentResult === hoverResult) { // avoid updating the DOM to avoid resetting the user selection return; @@ -214,36 +169,6 @@ export class ContentHoverController extends Disposable { } } - public hide(): void { - this._computer.anchor = null; - this._hoverOperation.cancel(); - this._setCurrentResult(null); - } - - public get isColorPickerVisible(): boolean { - return this._widget.isColorPickerVisible; - } - - public get isVisibleFromKeyboard(): boolean { - return this._widget.isVisibleFromKeyboard; - } - - public get isVisible(): boolean { - return this._widget.isVisible; - } - - public get isFocused(): boolean { - return this._widget.isFocused; - } - - public get isResizing(): boolean { - return this._widget.isResizing; - } - - public containsNode(node: Node | null | undefined): boolean { - return (node ? this._widget.getDomNode().contains(node) : false); - } - private _addLoadingMessage(result: IHoverPart[]): IHoverPart[] { if (this._computer.anchor) { for (const participant of this._participants) { @@ -277,7 +202,7 @@ export class ContentHoverController extends Disposable { } private _renderMessages(anchor: HoverAnchor, messages: IHoverPart[]): void { - const { showAtPosition, showAtSecondaryPosition, highlightRange } = ContentHoverController.computeHoverRanges(this._editor, anchor.range, messages); + const { showAtPosition, showAtSecondaryPosition, highlightRange } = ContentHoverWidget.computeHoverRanges(this._editor, anchor.range, messages); const disposables = new DisposableStore(); const statusBar = disposables.add(new EditorHoverStatusBar(this._keybindingService)); @@ -311,7 +236,7 @@ export class ContentHoverController extends Disposable { const highlightDecoration = this._editor.createDecorationsCollection(); highlightDecoration.set([{ range: highlightRange, - options: ContentHoverController._DECORATION_OPTIONS + options: ContentHoverWidget._DECORATION_OPTIONS }]); disposables.add(toDisposable(() => { highlightDecoration.clear(); @@ -319,6 +244,8 @@ export class ContentHoverController extends Disposable { } this._widget.showAt(fragment, new ContentHoverVisibleData( + anchor.initialMousePosX, + anchor.initialMousePosY, colorPicker, showAtPosition, showAtSecondaryPosition, @@ -326,8 +253,6 @@ export class ContentHoverController extends Disposable { this._computer.shouldFocus, this._computer.source, isBeforeContent, - anchor.initialMousePosX, - anchor.initialMousePosY, disposables )); } else { @@ -341,6 +266,7 @@ export class ContentHoverController extends Disposable { }); public static computeHoverRanges(editor: ICodeEditor, anchorRange: Range, messages: IHoverPart[]) { + let startColumnBoundary = 1; if (editor.hasModel()) { // Ensure the range is on the current view line @@ -350,11 +276,12 @@ export class ContentHoverController extends Disposable { const anchorViewRangeStart = new Position(anchorViewRange.startLineNumber, viewModel.getLineMinColumn(anchorViewRange.startLineNumber)); startColumnBoundary = coordinatesConverter.convertViewPositionToModelPosition(anchorViewRangeStart).column; } + // The anchor range is always on a single line const anchorLineNumber = anchorRange.startLineNumber; let renderStartColumn = anchorRange.startColumn; - let highlightRange: Range = messages[0].range; - let forceShowAtRange: Range | null = null; + let highlightRange = messages[0].range; + let forceShowAtRange = null; for (const msg of messages) { highlightRange = Range.plusRange(highlightRange, msg.range); @@ -367,13 +294,77 @@ export class ContentHoverController extends Disposable { } } + const showAtPosition = forceShowAtRange ? forceShowAtRange.getStartPosition() : new Position(anchorLineNumber, anchorRange.startColumn); + const showAtSecondaryPosition = forceShowAtRange ? forceShowAtRange.getStartPosition() : new Position(anchorLineNumber, renderStartColumn); + return { - showAtPosition: forceShowAtRange ? forceShowAtRange.getStartPosition() : new Position(anchorLineNumber, anchorRange.startColumn), - showAtSecondaryPosition: forceShowAtRange ? forceShowAtRange.getStartPosition() : new Position(anchorLineNumber, renderStartColumn), + showAtPosition, + showAtSecondaryPosition, highlightRange }; } + /** + * Returns true if the hover shows now or will show. + */ + public showsOrWillShow(mouseEvent: IEditorMouseEvent): boolean { + + if (this._widget.isResizing) { + return true; + } + + const anchorCandidates: HoverAnchor[] = []; + for (const participant of this._participants) { + if (participant.suggestHoverAnchor) { + const anchor = participant.suggestHoverAnchor(mouseEvent); + if (anchor) { + anchorCandidates.push(anchor); + } + } + } + + const target = mouseEvent.target; + + if (target.type === MouseTargetType.CONTENT_TEXT) { + anchorCandidates.push(new HoverRangeAnchor(0, target.range, mouseEvent.event.posx, mouseEvent.event.posy)); + } + + if (target.type === MouseTargetType.CONTENT_EMPTY) { + const epsilon = this._editor.getOption(EditorOption.fontInfo).typicalHalfwidthCharacterWidth / 2; + if ( + !target.detail.isAfterLines + && typeof target.detail.horizontalDistanceToText === 'number' + && target.detail.horizontalDistanceToText < epsilon + ) { + // Let hover kick in even when the mouse is technically in the empty area after a line, given the distance is small enough + anchorCandidates.push(new HoverRangeAnchor(0, target.range, mouseEvent.event.posx, mouseEvent.event.posy)); + } + } + + if (anchorCandidates.length === 0) { + return this._startShowingOrUpdateHover(null, HoverStartMode.Delayed, HoverStartSource.Mouse, false, mouseEvent); + } + + anchorCandidates.sort((a, b) => b.priority - a.priority); + return this._startShowingOrUpdateHover(anchorCandidates[0], HoverStartMode.Delayed, HoverStartSource.Mouse, false, mouseEvent); + } + + public startShowingAtRange(range: Range, mode: HoverStartMode, source: HoverStartSource, focus: boolean): void { + this._startShowingOrUpdateHover(new HoverRangeAnchor(0, range, undefined, undefined), mode, source, focus, null); + } + + public getWidgetContent(): string | undefined { + const node = this._widget.getDomNode(); + if (!node.textContent) { + return undefined; + } + return node.textContent; + } + + public containsNode(node: Node | null | undefined): boolean { + return (node ? this._widget.getDomNode().contains(node) : false); + } + public focus(): void { this._widget.focus(); } @@ -409,6 +400,36 @@ export class ContentHoverController extends Disposable { public goToBottom(): void { this._widget.goToBottom(); } + + public hide(): void { + this._computer.anchor = null; + this._hoverOperation.cancel(); + this._setCurrentResult(null); + } + + public get isColorPickerVisible(): boolean { + return this._widget.isColorPickerVisible; + } + + public get isVisibleFromKeyboard(): boolean { + return this._widget.isVisibleFromKeyboard; + } + + public get isVisible(): boolean { + return this._widget.isVisible; + } + + public get isFocused(): boolean { + return this._widget.isFocused; + } + + public get isResizing(): boolean { + return this._widget.isResizing; + } + + public get widget() { + return this._widget; + } } class HoverResult { @@ -449,6 +470,8 @@ class ContentHoverVisibleData { public closestMouseDistance: number | undefined = undefined; constructor( + public initialMousePosX: number | undefined, + public initialMousePosY: number | undefined, public readonly colorPicker: IEditorHoverColorPickerWidget | null, public readonly showAtPosition: Position, public readonly showAtSecondaryPosition: Position, @@ -456,8 +479,6 @@ class ContentHoverVisibleData { public readonly stoleFocus: boolean, public readonly source: HoverStartSource, public readonly isBeforeContent: boolean, - public initialMousePosX: number | undefined, - public initialMousePosY: number | undefined, public readonly disposables: DisposableStore ) { } } @@ -466,7 +487,7 @@ const HORIZONTAL_SCROLLING_BY = 30; const SCROLLBAR_WIDTH = 10; const CONTAINER_HEIGHT_PADDING = 6; -export class ContentHoverWidget extends ResizableContentWidget { +export class ResizableContentHoverWidget extends ResizableContentWidget { public static ID = 'editor.contrib.resizableContentHoverWidget'; private static _lastDimensions: dom.Dimension = new dom.Dimension(0, 0); @@ -507,6 +528,7 @@ export class ContentHoverWidget extends ResizableContentWidget { const minimumWidth = 150; const minimumSize = new dom.Dimension(minimumWidth, minimumHeight); super(editor, minimumSize); + this._minimumSize = minimumSize; this._hoverVisibleKey = EditorContextKeys.hoverVisible.bindTo(contextKeyService); this._hoverFocusedKey = EditorContextKeys.hoverFocused.bindTo(contextKeyService); @@ -542,7 +564,7 @@ export class ContentHoverWidget extends ResizableContentWidget { } public getId(): string { - return ContentHoverWidget.ID; + return ResizableContentHoverWidget.ID; } private static _applyDimensions(container: HTMLElement, width: number | string, height: number | string): void { @@ -554,12 +576,12 @@ export class ContentHoverWidget extends ResizableContentWidget { private _setContentsDomNodeDimensions(width: number | string, height: number | string): void { const contentsDomNode = this._hover.contentsDomNode; - return ContentHoverWidget._applyDimensions(contentsDomNode, width, height); + return ResizableContentHoverWidget._applyDimensions(contentsDomNode, width, height); } private _setContainerDomNodeDimensions(width: number | string, height: number | string): void { const containerDomNode = this._hover.containerDomNode; - return ContentHoverWidget._applyDimensions(containerDomNode, width, height); + return ResizableContentHoverWidget._applyDimensions(containerDomNode, width, height); } private _setHoverWidgetDimensions(width: number | string, height: number | string): void { @@ -576,8 +598,8 @@ export class ContentHoverWidget extends ResizableContentWidget { } private _setHoverWidgetMaxDimensions(width: number | string, height: number | string): void { - ContentHoverWidget._applyMaxDimensions(this._hover.contentsDomNode, width, height); - ContentHoverWidget._applyMaxDimensions(this._hover.containerDomNode, width, height); + ResizableContentHoverWidget._applyMaxDimensions(this._hover.contentsDomNode, width, height); + ResizableContentHoverWidget._applyMaxDimensions(this._hover.containerDomNode, width, height); this._hover.containerDomNode.style.setProperty('--vscode-hover-maxWidth', typeof width === 'number' ? `${width}px` : width); this._layoutContentWidget(); } @@ -616,7 +638,7 @@ export class ContentHoverWidget extends ResizableContentWidget { } protected override _resize(size: dom.Dimension): void { - ContentHoverWidget._lastDimensions = new dom.Dimension(size.width, size.height); + ResizableContentHoverWidget._lastDimensions = new dom.Dimension(size.width, size.height); this._setAdjustedHoverWidgetDimensions(size); this._resizableNode.layout(size.height, size.width); this._updateResizableNodeMaxDimensions(); @@ -630,7 +652,9 @@ export class ContentHoverWidget extends ResizableContentWidget { if (!position) { return; } - return this._positionPreference === ContentWidgetPositionPreference.ABOVE ? this._availableVerticalSpaceAbove(position) : this._availableVerticalSpaceBelow(position); + return this._positionPreference === ContentWidgetPositionPreference.ABOVE ? + this._availableVerticalSpaceAbove(position) + : this._availableVerticalSpaceBelow(position); } private _findMaximumRenderingHeight(): number | undefined { @@ -643,6 +667,7 @@ export class ContentHoverWidget extends ResizableContentWidget { Array.from(this._hover.contentsDomNode.children).forEach((hoverPart) => { maximumHeight += hoverPart.clientHeight; }); + if (this._hasHorizontalScrollbar()) { maximumHeight += SCROLLBAR_WIDTH; } @@ -670,7 +695,6 @@ export class ContentHoverWidget extends ResizableContentWidget { } const overflowing = this._isHoverTextOverflowing(); - const initialWidth = ( typeof this._contentWidth === 'undefined' ? 0 @@ -687,10 +711,14 @@ export class ContentHoverWidget extends ResizableContentWidget { } public isMouseGettingCloser(posx: number, posy: number): boolean { + if (!this._visibleData) { return false; } - if (typeof this._visibleData.initialMousePosX === 'undefined' || typeof this._visibleData.initialMousePosY === 'undefined') { + if ( + typeof this._visibleData.initialMousePosX === 'undefined' + || typeof this._visibleData.initialMousePosY === 'undefined' + ) { this._visibleData.initialMousePosX = posx; this._visibleData.initialMousePosY = posy; return false; @@ -698,13 +726,29 @@ export class ContentHoverWidget extends ResizableContentWidget { const widgetRect = dom.getDomNodePagePosition(this.getDomNode()); if (typeof this._visibleData.closestMouseDistance === 'undefined') { - this._visibleData.closestMouseDistance = computeDistanceFromPointToRectangle(this._visibleData.initialMousePosX, this._visibleData.initialMousePosY, widgetRect.left, widgetRect.top, widgetRect.width, widgetRect.height); + this._visibleData.closestMouseDistance = computeDistanceFromPointToRectangle( + this._visibleData.initialMousePosX, + this._visibleData.initialMousePosY, + widgetRect.left, + widgetRect.top, + widgetRect.width, + widgetRect.height + ); } - const distance = computeDistanceFromPointToRectangle(posx, posy, widgetRect.left, widgetRect.top, widgetRect.width, widgetRect.height); + + const distance = computeDistanceFromPointToRectangle( + posx, + posy, + widgetRect.left, + widgetRect.top, + widgetRect.width, + widgetRect.height + ); if (distance > this._visibleData.closestMouseDistance + 4 /* tolerance of 4 pixels */) { // The mouse is getting farther away return false; } + this._visibleData.closestMouseDistance = Math.min(this._visibleData.closestMouseDistance, distance); return true; } @@ -738,8 +782,8 @@ export class ContentHoverWidget extends ResizableContentWidget { } private _updateMaxDimensions() { - const height = Math.max(this._editor.getLayoutInfo().height / 4, 250, ContentHoverWidget._lastDimensions.height); - const width = Math.max(this._editor.getLayoutInfo().width * 0.66, 500, ContentHoverWidget._lastDimensions.width); + const height = Math.max(this._editor.getLayoutInfo().height / 4, 250, ResizableContentHoverWidget._lastDimensions.height); + const width = Math.max(this._editor.getLayoutInfo().width * 0.66, 500, ResizableContentHoverWidget._lastDimensions.width); this._setHoverWidgetMaxDimensions(width, height); } @@ -784,7 +828,11 @@ export class ContentHoverWidget extends ResizableContentWidget { hoverData.colorPicker?.layout(); // The aria label overrides the label, so if we add to it, add the contents of the hover const hoverFocused = this._hover.containerDomNode.ownerDocument.activeElement === this._hover.containerDomNode; - const accessibleViewHint = hoverFocused && getHoverAccessibleViewHint(this._configurationService.getValue('accessibility.verbosity.hover') === true && this._accessibilityService.isScreenReaderOptimized(), this._keybindingService.lookupKeybinding('editor.action.accessibleView')?.getAriaLabel() ?? ''); + const accessibleViewHint = hoverFocused && getHoverAccessibleViewHint( + this._configurationService.getValue('accessibility.verbosity.hover') === true && this._accessibilityService.isScreenReaderOptimized(), + this._keybindingService.lookupKeybinding('editor.action.accessibleView')?.getAriaLabel() ?? '' + ); + if (accessibleViewHint) { this._hover.contentsDomNode.ariaLabel = this._hover.contentsDomNode.textContent + ', ' + accessibleViewHint; } @@ -935,7 +983,13 @@ export class EditorHoverStatusBar extends Disposable implements IEditorHoverStat this.actionsElement = dom.append(this.hoverElement, $('div.actions')); } - public addAction(actionOptions: { label: string; iconClass?: string; run: (target: HTMLElement) => void; commandId: string }): IEditorHoverAction { + public addAction( + actionOptions: { + label: string; + iconClass?: string; run: (target: HTMLElement) => void; + commandId: string; + }): IEditorHoverAction { + const keybinding = this._keybindingService.lookupKeybinding(actionOptions.commandId); const keybindingLabel = keybinding ? keybinding.getLabel() : null; this._hasContent = true; @@ -987,6 +1041,7 @@ class ContentHoverComputer implements IHoverComputer { } const maxColumn = model.getLineMaxColumn(lineNumber); + return editor.getLineDecorations(lineNumber).filter((d) => { if (d.options.isWholeLine) { return true; @@ -994,6 +1049,7 @@ class ContentHoverComputer implements IHoverComputer { const startColumn = (d.range.startLineNumber === lineNumber) ? d.range.startColumn : 1; const endColumn = (d.range.endLineNumber === lineNumber) ? d.range.endColumn : maxColumn; + if (d.options.showIfCollapsed) { // Relax check around `showIfCollapsed` decorations to also include +/- 1 character if (startColumn > anchor.range.startColumn + 1 || anchor.range.endColumn - 1 > endColumn) { @@ -1017,6 +1073,7 @@ class ContentHoverComputer implements IHoverComputer { } const lineDecorations = ContentHoverComputer._getLineDecorations(this._editor, anchor); + return AsyncIterableObject.merge( this._participants.map((participant) => { if (!participant.computeAsync) { diff --git a/src/vs/editor/contrib/hover/browser/hover.ts b/src/vs/editor/contrib/hover/browser/hover.ts index f9d1c44c10e..44b953a191c 100644 --- a/src/vs/editor/contrib/hover/browser/hover.ts +++ b/src/vs/editor/contrib/hover/browser/hover.ts @@ -15,7 +15,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { ILanguageService } from 'vs/editor/common/languages/language'; import { GotoDefinitionAtPositionEditorContribution } from 'vs/editor/contrib/gotoSymbol/browser/link/goToDefinitionAtPosition'; import { HoverStartMode, HoverStartSource } from 'vs/editor/contrib/hover/browser/hoverOperation'; -import { ContentHoverWidget, ContentHoverController } from 'vs/editor/contrib/hover/browser/contentHover'; +import { ResizableContentHoverWidget, ContentHoverWidget } from 'vs/editor/contrib/hover/browser/contentHover'; import { MarginHoverWidget } from 'vs/editor/contrib/hover/browser/marginHover'; import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -44,7 +44,7 @@ export class ModesHoverController extends Disposable implements IEditorContribut private readonly _toUnhook = new DisposableStore(); - private _contentWidget: ContentHoverController | null; + private _contentWidget: ContentHoverWidget | null; getWidgetContent(): string | undefined { return this._contentWidget?.getWidgetContent(); } @@ -132,7 +132,7 @@ export class ModesHoverController extends Disposable implements IEditorContribut const target = mouseEvent.target; - if (target.type === MouseTargetType.CONTENT_WIDGET && target.detail === ContentHoverWidget.ID) { + if (target.type === MouseTargetType.CONTENT_WIDGET && target.detail === ResizableContentHoverWidget.ID) { this._hoverClicked = true; // mouse down on top of content hover widget return; @@ -173,7 +173,7 @@ export class ModesHoverController extends Disposable implements IEditorContribut if ( this._isHoverSticky && target.type === MouseTargetType.CONTENT_WIDGET - && target.detail === ContentHoverWidget.ID + && target.detail === ResizableContentHoverWidget.ID ) { // mouse moved on top of content hover widget return true; @@ -189,7 +189,7 @@ export class ModesHoverController extends Disposable implements IEditorContribut if ( !this._isHoverSticky && target.type === MouseTargetType.CONTENT_WIDGET - && target.detail === ContentHoverWidget.ID + && target.detail === ResizableContentHoverWidget.ID && this._contentWidget?.isColorPickerVisible ) { // though the hover is not sticky, the color picker needs to. @@ -264,7 +264,7 @@ export class ModesHoverController extends Disposable implements IEditorContribut const contentWidget = this._getOrCreateContentWidget(); - if (contentWidget.maybeShowAt(mouseEvent)) { + if (contentWidget.showsOrWillShow(mouseEvent)) { this._glyphWidget?.hide(); return; } @@ -324,9 +324,9 @@ export class ModesHoverController extends Disposable implements IEditorContribut this._contentWidget?.hide(); } - private _getOrCreateContentWidget(): ContentHoverController { + private _getOrCreateContentWidget(): ContentHoverWidget { if (!this._contentWidget) { - this._contentWidget = this._instantiationService.createInstance(ContentHoverController, this._editor); + this._contentWidget = this._instantiationService.createInstance(ContentHoverWidget, this._editor); } return this._contentWidget; } diff --git a/src/vs/editor/contrib/hover/test/browser/contentHover.test.ts b/src/vs/editor/contrib/hover/test/browser/contentHover.test.ts index cf05d439031..74140abdea8 100644 --- a/src/vs/editor/contrib/hover/test/browser/contentHover.test.ts +++ b/src/vs/editor/contrib/hover/test/browser/contentHover.test.ts @@ -7,7 +7,7 @@ import * as assert from 'assert'; import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; -import { ContentHoverController } from 'vs/editor/contrib/hover/browser/contentHover'; +import { ContentHoverWidget } from 'vs/editor/contrib/hover/browser/contentHover'; import { IHoverPart } from 'vs/editor/contrib/hover/browser/hoverTypes'; import { TestCodeEditorInstantiationOptions, withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor'; @@ -18,7 +18,7 @@ suite('Content Hover', () => { test('issue #151235: Gitlens hover shows up in the wrong place', () => { const text = 'just some text'; withTestCodeEditor(text, {}, (editor) => { - const actual = ContentHoverController.computeHoverRanges( + const actual = ContentHoverWidget.computeHoverRanges( editor, new Range(5, 5, 5, 5), [{ range: new Range(4, 1, 5, 6) }] @@ -38,7 +38,7 @@ suite('Content Hover', () => { const text = 'just some text'; const opts: TestCodeEditorInstantiationOptions = { wordWrap: 'wordWrapColumn', wordWrapColumn: 6 }; withTestCodeEditor(text, opts, (editor) => { - const actual = ContentHoverController.computeHoverRanges( + const actual = ContentHoverWidget.computeHoverRanges( editor, new Range(1, 8, 1, 8), [{ range: new Range(1, 1, 1, 15) }] From 287d9ab0e1437b5b514092bc32762272412ed06f Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Fri, 8 Dec 2023 15:55:23 +0100 Subject: [PATCH 2/2] undoing the rename --- .../contrib/hover/browser/contentHover.ts | 28 +++++++++---------- src/vs/editor/contrib/hover/browser/hover.ts | 14 +++++----- .../hover/test/browser/contentHover.test.ts | 6 ++-- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/vs/editor/contrib/hover/browser/contentHover.ts b/src/vs/editor/contrib/hover/browser/contentHover.ts index f5630ea7fc2..5572e8f5b3d 100644 --- a/src/vs/editor/contrib/hover/browser/contentHover.ts +++ b/src/vs/editor/contrib/hover/browser/contentHover.ts @@ -29,12 +29,12 @@ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessib const $ = dom.$; -export class ContentHoverWidget extends Disposable { +export class ContentHoverController extends Disposable { private _currentResult: HoverResult | null = null; private readonly _computer: ContentHoverComputer; - private readonly _widget: ResizableContentHoverWidget; + private readonly _widget: ContentHoverWidget; private readonly _participants: IEditorHoverParticipant[]; private readonly _hoverOperation: HoverOperation; @@ -45,7 +45,7 @@ export class ContentHoverWidget extends Disposable { ) { super(); - this._widget = this._register(this._instantiationService.createInstance(ResizableContentHoverWidget, this._editor)); + this._widget = this._register(this._instantiationService.createInstance(ContentHoverWidget, this._editor)); // Instantiate participants and sort them by `hoverOrdinal` which is relevant for rendering order. this._participants = []; @@ -202,7 +202,7 @@ export class ContentHoverWidget extends Disposable { } private _renderMessages(anchor: HoverAnchor, messages: IHoverPart[]): void { - const { showAtPosition, showAtSecondaryPosition, highlightRange } = ContentHoverWidget.computeHoverRanges(this._editor, anchor.range, messages); + const { showAtPosition, showAtSecondaryPosition, highlightRange } = ContentHoverController.computeHoverRanges(this._editor, anchor.range, messages); const disposables = new DisposableStore(); const statusBar = disposables.add(new EditorHoverStatusBar(this._keybindingService)); @@ -236,7 +236,7 @@ export class ContentHoverWidget extends Disposable { const highlightDecoration = this._editor.createDecorationsCollection(); highlightDecoration.set([{ range: highlightRange, - options: ContentHoverWidget._DECORATION_OPTIONS + options: ContentHoverController._DECORATION_OPTIONS }]); disposables.add(toDisposable(() => { highlightDecoration.clear(); @@ -487,7 +487,7 @@ const HORIZONTAL_SCROLLING_BY = 30; const SCROLLBAR_WIDTH = 10; const CONTAINER_HEIGHT_PADDING = 6; -export class ResizableContentHoverWidget extends ResizableContentWidget { +export class ContentHoverWidget extends ResizableContentWidget { public static ID = 'editor.contrib.resizableContentHoverWidget'; private static _lastDimensions: dom.Dimension = new dom.Dimension(0, 0); @@ -564,7 +564,7 @@ export class ResizableContentHoverWidget extends ResizableContentWidget { } public getId(): string { - return ResizableContentHoverWidget.ID; + return ContentHoverWidget.ID; } private static _applyDimensions(container: HTMLElement, width: number | string, height: number | string): void { @@ -576,12 +576,12 @@ export class ResizableContentHoverWidget extends ResizableContentWidget { private _setContentsDomNodeDimensions(width: number | string, height: number | string): void { const contentsDomNode = this._hover.contentsDomNode; - return ResizableContentHoverWidget._applyDimensions(contentsDomNode, width, height); + return ContentHoverWidget._applyDimensions(contentsDomNode, width, height); } private _setContainerDomNodeDimensions(width: number | string, height: number | string): void { const containerDomNode = this._hover.containerDomNode; - return ResizableContentHoverWidget._applyDimensions(containerDomNode, width, height); + return ContentHoverWidget._applyDimensions(containerDomNode, width, height); } private _setHoverWidgetDimensions(width: number | string, height: number | string): void { @@ -598,8 +598,8 @@ export class ResizableContentHoverWidget extends ResizableContentWidget { } private _setHoverWidgetMaxDimensions(width: number | string, height: number | string): void { - ResizableContentHoverWidget._applyMaxDimensions(this._hover.contentsDomNode, width, height); - ResizableContentHoverWidget._applyMaxDimensions(this._hover.containerDomNode, width, height); + ContentHoverWidget._applyMaxDimensions(this._hover.contentsDomNode, width, height); + ContentHoverWidget._applyMaxDimensions(this._hover.containerDomNode, width, height); this._hover.containerDomNode.style.setProperty('--vscode-hover-maxWidth', typeof width === 'number' ? `${width}px` : width); this._layoutContentWidget(); } @@ -638,7 +638,7 @@ export class ResizableContentHoverWidget extends ResizableContentWidget { } protected override _resize(size: dom.Dimension): void { - ResizableContentHoverWidget._lastDimensions = new dom.Dimension(size.width, size.height); + ContentHoverWidget._lastDimensions = new dom.Dimension(size.width, size.height); this._setAdjustedHoverWidgetDimensions(size); this._resizableNode.layout(size.height, size.width); this._updateResizableNodeMaxDimensions(); @@ -782,8 +782,8 @@ export class ResizableContentHoverWidget extends ResizableContentWidget { } private _updateMaxDimensions() { - const height = Math.max(this._editor.getLayoutInfo().height / 4, 250, ResizableContentHoverWidget._lastDimensions.height); - const width = Math.max(this._editor.getLayoutInfo().width * 0.66, 500, ResizableContentHoverWidget._lastDimensions.width); + const height = Math.max(this._editor.getLayoutInfo().height / 4, 250, ContentHoverWidget._lastDimensions.height); + const width = Math.max(this._editor.getLayoutInfo().width * 0.66, 500, ContentHoverWidget._lastDimensions.width); this._setHoverWidgetMaxDimensions(width, height); } diff --git a/src/vs/editor/contrib/hover/browser/hover.ts b/src/vs/editor/contrib/hover/browser/hover.ts index 44b953a191c..f4fb86e9868 100644 --- a/src/vs/editor/contrib/hover/browser/hover.ts +++ b/src/vs/editor/contrib/hover/browser/hover.ts @@ -15,7 +15,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { ILanguageService } from 'vs/editor/common/languages/language'; import { GotoDefinitionAtPositionEditorContribution } from 'vs/editor/contrib/gotoSymbol/browser/link/goToDefinitionAtPosition'; import { HoverStartMode, HoverStartSource } from 'vs/editor/contrib/hover/browser/hoverOperation'; -import { ResizableContentHoverWidget, ContentHoverWidget } from 'vs/editor/contrib/hover/browser/contentHover'; +import { ContentHoverWidget, ContentHoverController } from 'vs/editor/contrib/hover/browser/contentHover'; import { MarginHoverWidget } from 'vs/editor/contrib/hover/browser/marginHover'; import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -44,7 +44,7 @@ export class ModesHoverController extends Disposable implements IEditorContribut private readonly _toUnhook = new DisposableStore(); - private _contentWidget: ContentHoverWidget | null; + private _contentWidget: ContentHoverController | null; getWidgetContent(): string | undefined { return this._contentWidget?.getWidgetContent(); } @@ -132,7 +132,7 @@ export class ModesHoverController extends Disposable implements IEditorContribut const target = mouseEvent.target; - if (target.type === MouseTargetType.CONTENT_WIDGET && target.detail === ResizableContentHoverWidget.ID) { + if (target.type === MouseTargetType.CONTENT_WIDGET && target.detail === ContentHoverWidget.ID) { this._hoverClicked = true; // mouse down on top of content hover widget return; @@ -173,7 +173,7 @@ export class ModesHoverController extends Disposable implements IEditorContribut if ( this._isHoverSticky && target.type === MouseTargetType.CONTENT_WIDGET - && target.detail === ResizableContentHoverWidget.ID + && target.detail === ContentHoverWidget.ID ) { // mouse moved on top of content hover widget return true; @@ -189,7 +189,7 @@ export class ModesHoverController extends Disposable implements IEditorContribut if ( !this._isHoverSticky && target.type === MouseTargetType.CONTENT_WIDGET - && target.detail === ResizableContentHoverWidget.ID + && target.detail === ContentHoverWidget.ID && this._contentWidget?.isColorPickerVisible ) { // though the hover is not sticky, the color picker needs to. @@ -324,9 +324,9 @@ export class ModesHoverController extends Disposable implements IEditorContribut this._contentWidget?.hide(); } - private _getOrCreateContentWidget(): ContentHoverWidget { + private _getOrCreateContentWidget(): ContentHoverController { if (!this._contentWidget) { - this._contentWidget = this._instantiationService.createInstance(ContentHoverWidget, this._editor); + this._contentWidget = this._instantiationService.createInstance(ContentHoverController, this._editor); } return this._contentWidget; } diff --git a/src/vs/editor/contrib/hover/test/browser/contentHover.test.ts b/src/vs/editor/contrib/hover/test/browser/contentHover.test.ts index 74140abdea8..cf05d439031 100644 --- a/src/vs/editor/contrib/hover/test/browser/contentHover.test.ts +++ b/src/vs/editor/contrib/hover/test/browser/contentHover.test.ts @@ -7,7 +7,7 @@ import * as assert from 'assert'; import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; -import { ContentHoverWidget } from 'vs/editor/contrib/hover/browser/contentHover'; +import { ContentHoverController } from 'vs/editor/contrib/hover/browser/contentHover'; import { IHoverPart } from 'vs/editor/contrib/hover/browser/hoverTypes'; import { TestCodeEditorInstantiationOptions, withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor'; @@ -18,7 +18,7 @@ suite('Content Hover', () => { test('issue #151235: Gitlens hover shows up in the wrong place', () => { const text = 'just some text'; withTestCodeEditor(text, {}, (editor) => { - const actual = ContentHoverWidget.computeHoverRanges( + const actual = ContentHoverController.computeHoverRanges( editor, new Range(5, 5, 5, 5), [{ range: new Range(4, 1, 5, 6) }] @@ -38,7 +38,7 @@ suite('Content Hover', () => { const text = 'just some text'; const opts: TestCodeEditorInstantiationOptions = { wordWrap: 'wordWrapColumn', wordWrapColumn: 6 }; withTestCodeEditor(text, opts, (editor) => { - const actual = ContentHoverWidget.computeHoverRanges( + const actual = ContentHoverController.computeHoverRanges( editor, new Range(1, 8, 1, 8), [{ range: new Range(1, 1, 1, 15) }]