From 0b76a78c4788caee17c6dbe96f7f7359d52ba168 Mon Sep 17 00:00:00 2001 From: vince-fugnitto Date: Thu, 15 Jun 2023 13:11:56 -0400 Subject: [PATCH] terminal: fix `split-terminal` visibility The commit fixes the terminal `split-terminal` toolbar item from appearing in other views when the terminal is active. Signed-off-by: vince-fugnitto --- .../src/browser/terminal-frontend-contribution.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/terminal/src/browser/terminal-frontend-contribution.ts b/packages/terminal/src/browser/terminal-frontend-contribution.ts index 055992fe8d3d5..bd31ca3a32968 100644 --- a/packages/terminal/src/browser/terminal-frontend-contribution.ts +++ b/packages/terminal/src/browser/terminal-frontend-contribution.ts @@ -32,7 +32,7 @@ import { import { ApplicationShell, KeybindingContribution, KeyCode, Key, WidgetManager, PreferenceService, KeybindingRegistry, LabelProvider, WidgetOpenerOptions, StorageService, QuickInputService, - codicon, CommonCommands, FrontendApplicationContribution, OnWillStopAction, Dialog, ConfirmDialog, FrontendApplication, PreferenceScope + codicon, CommonCommands, FrontendApplicationContribution, OnWillStopAction, Dialog, ConfirmDialog, FrontendApplication, PreferenceScope, Widget } from '@theia/core/lib/browser'; import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar'; import { TERMINAL_WIDGET_FACTORY_ID, TerminalWidgetFactoryOptions, TerminalWidgetImpl } from './terminal-widget-impl'; @@ -543,8 +543,8 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu }); commands.registerCommand(TerminalCommands.SPLIT, { execute: () => this.splitTerminal(), - isEnabled: () => this.shell.currentWidget instanceof TerminalWidget, - isVisible: () => this.shell.currentWidget instanceof TerminalWidget, + isEnabled: w => this.withWidget(w, () => true), + isVisible: w => this.withWidget(w, () => true), }); commands.registerCommand(TerminalCommands.TERMINAL_CLEAR); commands.registerHandler(TerminalCommands.TERMINAL_CLEAR.id, { @@ -1022,6 +1022,13 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu this.open(termWidget, { widgetOptions: options }); } + protected withWidget(widget: Widget | undefined, fn: (widget: TerminalWidget) => T): T | false { + if (widget instanceof TerminalWidget) { + return fn(widget); + } + return false; + } + /** * It should be aligned with https://code.visualstudio.com/api/references/theme-color#integrated-terminal-colors */