[Refactoring] Adding IHoverWidget interface and using switch statement in the _tryShowHoverWidget code (#210192)

adding interface and using switch statement
This commit is contained in:
Aiday Marlen Kyzy 2024-04-12 08:54:52 +02:00 committed by GitHub
parent 50c781be18
commit f2eff1c6e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 36 additions and 10 deletions

View file

@ -17,7 +17,7 @@ import { IModelDecoration, PositionAffinity } from 'vs/editor/common/model';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import { TokenizationRegistry } from 'vs/editor/common/languages';
import { HoverOperation, HoverStartMode, HoverStartSource, IHoverComputer } from 'vs/editor/contrib/hover/browser/hoverOperation';
import { HoverAnchor, HoverAnchorType, HoverParticipantRegistry, HoverRangeAnchor, IEditorHoverColorPickerWidget, IEditorHoverAction, IEditorHoverParticipant, IEditorHoverRenderContext, IEditorHoverStatusBar, IHoverPart } from 'vs/editor/contrib/hover/browser/hoverTypes';
import { HoverAnchor, HoverAnchorType, HoverParticipantRegistry, HoverRangeAnchor, IEditorHoverColorPickerWidget, IEditorHoverAction, IEditorHoverParticipant, IEditorHoverRenderContext, IEditorHoverStatusBar, IHoverPart, IHoverWidget } from 'vs/editor/contrib/hover/browser/hoverTypes';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { AsyncIterableObject } from 'vs/base/common/async';
@ -29,7 +29,7 @@ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessib
const $ = dom.$;
export class ContentHoverController extends Disposable {
export class ContentHoverController extends Disposable implements IHoverWidget {
private _currentResult: HoverResult | null = null;
@ -304,9 +304,6 @@ export class ContentHoverController extends Disposable {
};
}
/**
* Returns true if the hover shows now or will show.
*/
public showsOrWillShow(mouseEvent: IEditorMouseEvent): boolean {
if (this._widget.isResizing) {

View file

@ -21,7 +21,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { editorHoverBorder } from 'vs/platform/theme/common/colorRegistry';
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { HoverParticipantRegistry } from 'vs/editor/contrib/hover/browser/hoverTypes';
import { HoverParticipantRegistry, IHoverWidget } from 'vs/editor/contrib/hover/browser/hoverTypes';
import { MarkdownHoverParticipant } from 'vs/editor/contrib/hover/browser/markdownHoverParticipant';
import { MarkerHoverParticipant } from 'vs/editor/contrib/hover/browser/markerHoverParticipant';
import { InlineSuggestionHintsContentWidget } from 'vs/editor/contrib/inlineCompletions/browser/inlineCompletionsHintsWidget';
@ -286,9 +286,23 @@ export class HoverController extends Disposable implements IEditorContribution {
}
private _tryShowHoverWidget(mouseEvent: IEditorMouseEvent, hoverWidgetType: HoverWidgetType): boolean {
const isContentWidget = hoverWidgetType === HoverWidgetType.Content;
const currentWidget = isContentWidget ? this._getOrCreateContentWidget() : this._getOrCreateGlyphWidget();
const otherWidget = isContentWidget ? this._getOrCreateGlyphWidget() : this._getOrCreateContentWidget();
const contentWidget: IHoverWidget = this._getOrCreateContentWidget();
const glyphWidget: IHoverWidget = this._getOrCreateGlyphWidget();
let currentWidget: IHoverWidget;
let otherWidget: IHoverWidget;
switch (hoverWidgetType) {
case HoverWidgetType.Content:
currentWidget = contentWidget;
otherWidget = glyphWidget;
break;
case HoverWidgetType.Glyph:
currentWidget = glyphWidget;
otherWidget = contentWidget;
break;
default:
throw new Error(`HoverWidgetType ${hoverWidgetType} is unrecognized`)
}
const showsOrWillShow = currentWidget.showsOrWillShow(mouseEvent);
if (showsOrWillShow) {
otherWidget.hide();

View file

@ -145,3 +145,17 @@ export const HoverParticipantRegistry = (new class HoverParticipantRegistry {
}
}());
export interface IHoverWidget {
/**
* Returns whether the hover widget is shown or should show in the future.
* If the widget should show, this triggers the display.
* @param mouseEvent editor mouse event
*/
showsOrWillShow(mouseEvent: IEditorMouseEvent): boolean;
/**
* Hides the hover.
*/
hide(): void;
}

View file

@ -15,6 +15,7 @@ import { HoverOperation, HoverStartMode, IHoverComputer } from 'vs/editor/contri
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { HoverWidget } from 'vs/base/browser/ui/hover/hoverWidget';
import { GlyphMarginLane } from 'vs/editor/common/model';
import { IHoverWidget } from 'vs/editor/contrib/hover/browser/hoverTypes';
const $ = dom.$;
@ -24,7 +25,7 @@ export interface IHoverMessage {
type LaneOrLineNumber = GlyphMarginLane | 'lineNo';
export class MarginHoverWidget extends Disposable implements IOverlayWidget {
export class MarginHoverWidget extends Disposable implements IOverlayWidget, IHoverWidget {
public static readonly ID = 'editor.contrib.modesGlyphHoverWidget';