Skip to content

Commit

Permalink
fix #126252
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge committed Jun 18, 2021
1 parent 3ebacf6 commit 31aad2a
Showing 1 changed file with 70 additions and 45 deletions.
115 changes: 70 additions & 45 deletions src/vs/workbench/contrib/terminal/browser/terminalQuickAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { localize } from 'vs/nls';
import { IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
import { IPickerQuickAccessItem, PickerQuickAccessProvider, TriggerAction } from 'vs/platform/quickinput/browser/pickerQuickAccess';
import { matchesFuzzy } from 'vs/base/common/filters';
import { ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { ITerminalEditorService, ITerminalInstance, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
import { TerminalCommandId, TerminalLocation } from 'vs/workbench/contrib/terminal/common/terminal';
import { IThemeService, ThemeIcon } from 'vs/platform/theme/common/themeService';
import { killTerminalIcon, renameTerminalIcon } from 'vs/workbench/contrib/terminal/browser/terminalIcons';
import { getColorClass, getIconId, getUriClasses } from 'vs/workbench/contrib/terminal/browser/terminalIcon';
Expand All @@ -21,6 +21,7 @@ export class TerminalQuickAccessProvider extends PickerQuickAccessProvider<IPick

constructor(
@ITerminalService private readonly _terminalService: ITerminalService,
@ITerminalEditorService private readonly _terminalEditorService: ITerminalEditorService,
@ICommandService private readonly _commandService: ICommandService,
@IThemeService private readonly _themeService: IThemeService
) {
Expand All @@ -35,51 +36,22 @@ export class TerminalQuickAccessProvider extends PickerQuickAccessProvider<IPick
const terminalGroup = terminalGroups[groupIndex];
for (let terminalIndex = 0; terminalIndex < terminalGroup.terminalInstances.length; terminalIndex++) {
const terminal = terminalGroup.terminalInstances[terminalIndex];
const iconId = getIconId(terminal);
const label = `$(${iconId}) ${groupIndex + 1}.${terminalIndex + 1}: ${terminal.title}`;
const iconClasses: string[] = [];
const colorClass = getColorClass(terminal);
if (colorClass) {
iconClasses.push(colorClass);
const pick = this._createPick(terminal, terminalIndex, filter, groupIndex);
if (pick) {
terminalPicks.push(pick);
}
const uriClasses = getUriClasses(terminal, this._themeService.getColorTheme().type);
if (uriClasses) {
iconClasses.push(...uriClasses);
}
const highlights = matchesFuzzy(filter, label, true);
if (highlights) {
terminalPicks.push({
label,
highlights: { label: highlights },
buttons: [
{
iconClass: ThemeIcon.asClassName(renameTerminalIcon),
tooltip: localize('renameTerminal', "Rename Terminal")
},
{
iconClass: ThemeIcon.asClassName(killTerminalIcon),
tooltip: terminalStrings.kill.value
}
],
iconClasses,
trigger: buttonIndex => {
switch (buttonIndex) {
case 0:
this._commandService.executeCommand(TerminalCommandId.Rename, terminal);
return TriggerAction.NO_ACTION;
case 1:
terminal.dispose(true);
return TriggerAction.REMOVE_ITEM;
}
}
}

return TriggerAction.NO_ACTION;
},
accept: (keyMod, event) => {
this._terminalService.setActiveInstance(terminal);
this._terminalService.showPanel(!event.inBackground);
}
});
}
if (terminalPicks.length > 0) {
terminalPicks.push({ type: 'separator' });
}

const terminalEditors = this._terminalEditorService.terminalEditorInstances;
for (let editorIndex = 0; editorIndex < terminalEditors.length; editorIndex++) {
const pick = this._createPick(terminalEditors[editorIndex], terminalPicks.length + editorIndex, filter);
if (pick) {
terminalPicks.push(pick);
}
}

Expand All @@ -103,4 +75,57 @@ export class TerminalQuickAccessProvider extends PickerQuickAccessProvider<IPick
return terminalPicks;

}

private _createPick(terminal: ITerminalInstance, terminalIndex: number, filter: string, groupIndex?: number): IPickerQuickAccessItem | undefined {
const iconId = getIconId(terminal);
const label = groupIndex ? `$(${iconId}) ${groupIndex + 1}.${terminalIndex + 1}: ${terminal.title}` : `$(${iconId}) .${terminalIndex + 1}: ${terminal.title}`;
const iconClasses: string[] = [];
const colorClass = getColorClass(terminal);
if (colorClass) {
iconClasses.push(colorClass);
}
const uriClasses = getUriClasses(terminal, this._themeService.getColorTheme().type);
if (uriClasses) {
iconClasses.push(...uriClasses);
}
const highlights = matchesFuzzy(filter, label, true);
if (highlights) {
return {
label,
highlights: { label: highlights },
buttons: [
{
iconClass: ThemeIcon.asClassName(renameTerminalIcon),
tooltip: localize('renameTerminal', "Rename Terminal")
},
{
iconClass: ThemeIcon.asClassName(killTerminalIcon),
tooltip: terminalStrings.kill.value
}
],
iconClasses,
trigger: buttonIndex => {
switch (buttonIndex) {
case 0:
this._commandService.executeCommand(TerminalCommandId.Rename, terminal);
return TriggerAction.NO_ACTION;
case 1:
terminal.dispose(true);
return TriggerAction.REMOVE_ITEM;
}

return TriggerAction.NO_ACTION;
},
accept: (keyMod, event) => {
if (terminal.target === TerminalLocation.TerminalView) {
this._terminalService.showPanel(!event.inBackground);
this._terminalService.setActiveInstance(terminal);
} else {
this._terminalEditorService.createEditor(terminal);
}
}
};
}
return undefined;
}
}

0 comments on commit 31aad2a

Please sign in to comment.