Skip to content

Commit

Permalink
Merge pull request #186590 from microsoft/tyriar/177774
Browse files Browse the repository at this point in the history
Move single terminal tab to hover service
  • Loading branch information
Tyriar authored Jun 30, 2023
2 parents acf1af0 + 8c9bbe5 commit 072d222
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions src/vs/workbench/contrib/terminal/browser/terminalView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ import { getColorClass, getUriClasses } from 'vs/workbench/contrib/terminal/brow
import { withNullAsUndefined } from 'vs/base/common/types';
import { getTerminalActionBarArgs } from 'vs/workbench/contrib/terminal/browser/terminalMenus';
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey';
import { getShellIntegrationTooltip, getShellProcessTooltip } from 'vs/workbench/contrib/terminal/browser/terminalTooltip';
import { getInstanceHoverInfo } from 'vs/workbench/contrib/terminal/browser/terminalTooltip';
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { TerminalCapability } from 'vs/platform/terminal/common/capabilities/capabilities';
import { defaultSelectBoxStyles } from 'vs/platform/theme/browser/defaultStyles';
import { Event } from 'vs/base/common/event';
import { IHoverDelegate, IHoverDelegateOptions } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate';
import { IHoverService } from 'vs/workbench/services/hover/browser/hover';

export class TerminalViewPane extends ViewPane {
private _fontStyleElement: HTMLElement | undefined;
Expand Down Expand Up @@ -351,7 +353,10 @@ class SingleTerminalTabActionViewItem extends MenuEntryActionViewItem {
@ICommandService private readonly _commandService: ICommandService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
) {
super(action, { draggable: true }, keybindingService, notificationService, contextKeyService, themeService, contextMenuService);
super(action, {
draggable: true,
hoverDelegate: _instantiationService.createInstance(SingleTabHoverDelegate)
}, keybindingService, notificationService, contextKeyService, themeService, contextMenuService);

// Register listeners to update the tab
this._register(Event.debounce<ITerminalInstance | undefined, Set<ITerminalInstance>>(Event.any(
Expand Down Expand Up @@ -468,7 +473,6 @@ class SingleTerminalTabActionViewItem extends MenuEntryActionViewItem {
this._altCommand = `alt-command`;
label.classList.add(this._altCommand);
}
this._action.tooltip = getSingleTabTooltip(instance, this._terminalService.configHelper.config.tabs.separator);
this.updateTooltip();
}
}
Expand Down Expand Up @@ -498,16 +502,6 @@ function getSingleTabLabel(accessor: ServicesAccessor, instance: ITerminalInstan
return `${label} $(${primaryStatus.icon.id})`;
}

function getSingleTabTooltip(instance: ITerminalInstance | undefined, separator: string): string {
if (!instance) {
return '';
}
const parts: string[] = [];
parts.push(getSingleTabTitle(instance, separator) + getShellProcessTooltip(instance, false) + getShellIntegrationTooltip(instance, false));
parts.push(instance.statusList.primary?.tooltip || '');
return parts.filter(e => e).join('\n\n');
}

function getSingleTabTitle(instance: ITerminalInstance | undefined, separator: string): string {
if (!instance) {
return '';
Expand Down Expand Up @@ -585,3 +579,39 @@ class TerminalThemeIconStyle extends Themable {
this._styleElement.textContent = css;
}
}

class SingleTabHoverDelegate implements IHoverDelegate {
private _lastHoverHideTime: number = 0;

readonly placement = 'element';

constructor(
@IConfigurationService private readonly _configurationService: IConfigurationService,
@IHoverService private readonly _hoverService: IHoverService,
@ITerminalGroupService private readonly _terminalGroupService: ITerminalGroupService
) {
}

get delay(): number {
return Date.now() - this._lastHoverHideTime < 200
? 0 // show instantly when a hover was recently shown
: this._configurationService.getValue<number>('workbench.hover.delay');
}

showHover(options: IHoverDelegateOptions, focus?: boolean) {
const instance = this._terminalGroupService.activeInstance;
if (!instance) {
return;
}
const hoverInfo = getInstanceHoverInfo(instance);
return this._hoverService.showHover({
...options,
content: hoverInfo.content,
actions: hoverInfo.actions
}, focus);
}

onDidHideHover() {
this._lastHoverHideTime = Date.now();
}
}

0 comments on commit 072d222

Please sign in to comment.