Skip to content

Commit

Permalink
Hoverservice has it's own contextview instance (#206151)
Browse files Browse the repository at this point in the history
Hoverservice with it's own context view
  • Loading branch information
benibenj committed Feb 26, 2024
1 parent a389ff1 commit 2c045ae
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
20 changes: 12 additions & 8 deletions src/vs/editor/browser/services/hoverService/hoverService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { editorHoverBorder } from 'vs/platform/theme/common/colorRegistry';
import { IHoverService, IHoverOptions } from 'vs/platform/hover/browser/hover';
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { HoverWidget } from 'vs/editor/browser/services/hoverService/hoverWidget';
import { IContextViewProvider, IDelegate } from 'vs/base/browser/ui/contextview/contextview';
import { DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { Disposable, DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { addDisposableListener, EventType, getActiveElement, isAncestorOfActiveElement, isAncestor, getWindow } from 'vs/base/browser/dom';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
Expand All @@ -20,10 +20,12 @@ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessib
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
import { mainWindow } from 'vs/base/browser/window';
import { IHoverWidget } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate';
import { ContextViewHandler } from 'vs/platform/contextview/browser/contextViewService';

export class HoverService implements IHoverService {
export class HoverService extends Disposable implements IHoverService {
declare readonly _serviceBrand: undefined;

private _contextViewHandler: IContextViewProvider;
private _currentHoverOptions: IHoverOptions | undefined;
private _currentHover: HoverWidget | undefined;
private _lastHoverOptions: IHoverOptions | undefined;
Expand All @@ -32,13 +34,15 @@ export class HoverService implements IHoverService {

constructor(
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IContextViewService private readonly _contextViewService: IContextViewService,
@IContextMenuService contextMenuService: IContextMenuService,
@IKeybindingService private readonly _keybindingService: IKeybindingService,
@ILayoutService private readonly _layoutService: ILayoutService,
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService
) {
super();

contextMenuService.onDidShowContextMenu(() => this.hideHover());
this._contextViewHandler = this._register(new ContextViewHandler(this._layoutService));
}

showHover(options: IHoverOptions, focus?: boolean, skipLastFocusedUpdate?: boolean): IHoverWidget | undefined {
Expand Down Expand Up @@ -84,12 +88,12 @@ export class HoverService implements IHoverService {
const targetElement = options.target instanceof HTMLElement ? options.target : options.target.targetElements[0];
options.container = this._layoutService.getContainer(getWindow(targetElement));
}
const provider = this._contextViewService as IContextViewProvider;
provider.showContextView(

this._contextViewHandler.showContextView(
new HoverContextViewDelegate(hover, focus),
options.container
);
hover.onRequestLayout(() => provider.layout());
hover.onRequestLayout(() => this._contextViewHandler.layout());
if (options.persistence?.sticky) {
hoverDisposables.add(addDisposableListener(getWindow(options.container).document, EventType.MOUSE_DOWN, e => {
if (!isAncestor(e.target as HTMLElement, hover.domNode)) {
Expand Down Expand Up @@ -136,7 +140,7 @@ export class HoverService implements IHoverService {
private doHideHover(): void {
this._currentHover = undefined;
this._currentHoverOptions = undefined;
this._contextViewService.hideContextView();
this._contextViewHandler.hideContextView();
}

private _intersectionChange(entries: IntersectionObserverEntry[], hover: IDisposable): void {
Expand Down
20 changes: 12 additions & 8 deletions src/vs/platform/contextview/browser/contextViewService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ContextView, ContextViewDOMPosition } from 'vs/base/browser/ui/contextview/contextview';
import { ContextView, ContextViewDOMPosition, IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview';
import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
import { IContextViewDelegate, IContextViewService } from './contextView';
import { getWindow } from 'vs/base/browser/dom';

export class ContextViewService extends Disposable implements IContextViewService {

declare readonly _serviceBrand: undefined;
export class ContextViewHandler extends Disposable implements IContextViewProvider {

private currentViewDisposable: IDisposable = Disposable.None;
private readonly contextView = this._register(new ContextView(this.layoutService.mainContainer, ContextViewDOMPosition.ABSOLUTE));
protected readonly contextView = this._register(new ContextView(this.layoutService.mainContainer, ContextViewDOMPosition.ABSOLUTE));

constructor(
@ILayoutService private readonly layoutService: ILayoutService
Expand Down Expand Up @@ -55,10 +54,6 @@ export class ContextViewService extends Disposable implements IContextViewServic
return disposable;
}

getContextViewElement(): HTMLElement {
return this.contextView.getViewElement();
}

layout(): void {
this.contextView.layout();
}
Expand All @@ -74,3 +69,12 @@ export class ContextViewService extends Disposable implements IContextViewServic
this.currentViewDisposable = Disposable.None;
}
}

export class ContextViewService extends ContextViewHandler implements IContextViewService {

declare readonly _serviceBrand: undefined;

getContextViewElement(): HTMLElement {
return this.contextView.getViewElement();
}
}
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { Codicon } from 'vs/base/common/codicons';
import { defaultBreadcrumbsWidgetStyles } from 'vs/platform/theme/browser/defaultStyles';
import { Emitter } from 'vs/base/common/event';
import { IHoverDelegate } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate';
import { nativeHoverDelegate } from 'vs/platform/hover/browser/hover';
import { getDefaultHoverDelegate } from 'vs/base/browser/ui/hover/hoverDelegate';

class OutlineItem extends BreadcrumbsItem {

Expand Down Expand Up @@ -229,7 +229,7 @@ export class BreadcrumbsControl {
this._ckBreadcrumbsVisible = BreadcrumbsControl.CK_BreadcrumbsVisible.bindTo(this._contextKeyService);
this._ckBreadcrumbsActive = BreadcrumbsControl.CK_BreadcrumbsActive.bindTo(this._contextKeyService);

this._hoverDelegate = nativeHoverDelegate;
this._hoverDelegate = getDefaultHoverDelegate('mouse');

this._disposables.add(breadcrumbsService.register(this._editorGroup.id, this._widget));
this.hide();
Expand Down
7 changes: 2 additions & 5 deletions src/vs/workbench/browser/parts/editor/breadcrumbsPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import { IOutline, IOutlineComparator } from 'vs/workbench/services/outline/brow
import { IEditorOptions } from 'vs/platform/editor/common/editor';
import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { ITextResourceConfigurationService } from 'vs/editor/common/services/textResourceConfiguration';
import { IHoverDelegate } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate';
import { nativeHoverDelegate } from 'vs/platform/hover/browser/hover';

interface ILayoutInfo {
maxHeight: number;
Expand Down Expand Up @@ -215,13 +213,12 @@ class FileRenderer implements ITreeRenderer<IFileStat | IWorkspaceFolder, FuzzyS

constructor(
private readonly _labels: ResourceLabels,
private readonly _hoverDelegate: IHoverDelegate,
@IConfigurationService private readonly _configService: IConfigurationService,
) { }


renderTemplate(container: HTMLElement): IResourceLabel {
return this._labels.create(container, { supportHighlights: true, hoverDelegate: this._hoverDelegate });
return this._labels.create(container, { supportHighlights: true });
}

renderElement(node: ITreeNode<IWorkspaceFolder | IFileStat, [number, number, number]>, index: number, templateData: IResourceLabel): void {
Expand Down Expand Up @@ -377,7 +374,7 @@ export class BreadcrumbsFilePicker extends BreadcrumbsPicker {
'BreadcrumbsFilePicker',
container,
new FileVirtualDelegate(),
[this._instantiationService.createInstance(FileRenderer, labels, nativeHoverDelegate)],
[this._instantiationService.createInstance(FileRenderer, labels)],
this._instantiationService.createInstance(FileDataSource),
{
multipleSelectionSupport: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import { IListAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget';
import { IOutlineComparator, OutlineConfigKeys, OutlineTarget } from 'vs/workbench/services/outline/browser/outline';
import { ThemeIcon } from 'vs/base/common/themables';
import { mainWindow } from 'vs/base/browser/window';
import { IHoverDelegate } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate';
import { getDefaultHoverDelegate } from 'vs/base/browser/ui/hover/hoverDelegate';
import { nativeHoverDelegate } from 'vs/platform/hover/browser/hover';

export type DocumentSymbolItem = OutlineGroup | OutlineElement;

Expand Down Expand Up @@ -118,20 +115,16 @@ export class DocumentSymbolRenderer implements ITreeRenderer<OutlineElement, Fuz

readonly templateId: string = DocumentSymbolTemplate.id;

private _hoverDelegate: IHoverDelegate;

constructor(
private _renderMarker: boolean,
target: OutlineTarget,
@IConfigurationService private readonly _configurationService: IConfigurationService,
@IThemeService private readonly _themeService: IThemeService,
) {
this._hoverDelegate = target === OutlineTarget.OutlinePane ? getDefaultHoverDelegate('mouse') : nativeHoverDelegate;
}
) { }

renderTemplate(container: HTMLElement): DocumentSymbolTemplate {
container.classList.add('outline-element');
const iconLabel = new IconLabel(container, { supportHighlights: true, hoverDelegate: this._hoverDelegate });
const iconLabel = new IconLabel(container, { supportHighlights: true });
const iconClass = dom.$('.outline-element-icon');
const decoration = dom.$('.outline-element-decoration');
container.prepend(iconClass);
Expand Down

0 comments on commit 2c045ae

Please sign in to comment.