mirror of
https://github.com/Microsoft/vscode
synced 2024-09-18 01:58:27 +00:00
[Refactoring] Adding IHoverWidget interface and using switch statement in the _tryShowHoverWidget
code (#210192)
adding interface and using switch statement
This commit is contained in:
parent
50c781be18
commit
f2eff1c6e1
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
Loading…
Reference in a new issue