@@ -30,7 +30,6 @@ define(function (require, exports, module) {
3030
3131 const AppInit = require ( "utils/AppInit" ) ;
3232 const CommandManager = require ( "command/CommandManager" ) ;
33- const Menus = require ( "command/Menus" ) ;
3433 const WorkspaceManager = require ( "view/WorkspaceManager" ) ;
3534 const ProjectManager = require ( "project/ProjectManager" ) ;
3635 const ExtensionUtils = require ( "utils/ExtensionUtils" ) ;
@@ -40,6 +39,7 @@ define(function (require, exports, module) {
4039 const Strings = require ( "strings" ) ;
4140 const StringUtils = require ( "utils/StringUtils" ) ;
4241
42+ const Commands = require ( "command/Commands" ) ;
4343 const TerminalInstance = require ( "./TerminalInstance" ) ;
4444 const ShellProfiles = require ( "./ShellProfiles" ) ;
4545 const panelHTML = require ( "text!./terminal-panel.html" ) ;
@@ -48,7 +48,7 @@ define(function (require, exports, module) {
4848 ExtensionUtils . loadStyleSheet ( module , "../../thirdparty/xterm/xterm.css" ) ;
4949
5050 // Constants
51- const CMD_TOGGLE_TERMINAL = "terminal.toggle" ;
51+ const CMD_VIEW_TERMINAL = Commands . VIEW_TERMINAL ;
5252 const CMD_NEW_TERMINAL = "terminal.new" ;
5353 const PANEL_ID = "terminal-panel" ;
5454 const PANEL_MIN_SIZE = 100 ;
@@ -254,7 +254,7 @@ define(function (require, exports, module) {
254254 // Show panel if hidden
255255 if ( ! panel . isVisible ( ) ) {
256256 panel . show ( ) ;
257- _updateToolbarIcon ( true ) ;
257+
258258 }
259259
260260 // Spawn PTY process
@@ -329,7 +329,7 @@ define(function (require, exports, module) {
329329 // If no terminals left, hide the panel
330330 if ( terminalInstances . length === 0 ) {
331331 panel . hide ( ) ;
332- _updateToolbarIcon ( false ) ;
332+
333333 }
334334
335335 _updateFlyout ( ) ;
@@ -467,23 +467,28 @@ define(function (require, exports, module) {
467467 }
468468
469469 /**
470- * Toggle the terminal panel visibility
470+ * Show the terminal panel. Creates a new terminal if none exist.
471+ * If the panel is visible and the active terminal is focused and there
472+ * are 2+ terminals, cycles to the next one. Otherwise just shows and
473+ * focuses the active terminal.
471474 */
472- function _togglePanel ( ) {
473- if ( panel . isVisible ( ) ) {
474- panel . hide ( ) ;
475- _updateToolbarIcon ( false ) ;
475+ function _showTerminal ( ) {
476+ if ( terminalInstances . length === 0 ) {
477+ _createNewTerminal ( ) ;
478+ return ;
479+ }
480+ const active = _getActiveTerminal ( ) ;
481+ const terminalHasFocus = active && active . $container &&
482+ active . $container [ 0 ] . contains ( document . activeElement ) ;
483+ if ( terminalInstances . length >= 2 && panel . isVisible ( ) && terminalHasFocus ) {
484+ const activeIdx = terminalInstances . findIndex ( t => t . id === activeTerminalId ) ;
485+ const nextIdx = ( activeIdx + 1 ) % terminalInstances . length ;
486+ _activateTerminal ( terminalInstances [ nextIdx ] . id ) ;
476487 } else {
477- if ( terminalInstances . length === 0 ) {
478- _createNewTerminal ( ) ;
479- } else {
480- panel . show ( ) ;
481- _updateToolbarIcon ( true ) ;
482- const active = _getActiveTerminal ( ) ;
483- if ( active ) {
484- active . handleResize ( ) ;
485- active . focus ( ) ;
486- }
488+ panel . show ( ) ;
489+ if ( active ) {
490+ active . handleResize ( ) ;
491+ active . focus ( ) ;
487492 }
488493 }
489494 }
@@ -507,18 +512,6 @@ define(function (require, exports, module) {
507512 }
508513 }
509514
510- /**
511- * Update toolbar icon active state
512- */
513- function _updateToolbarIcon ( isActive ) {
514- const $icon = $ ( "#toolbar-terminal" ) ;
515- if ( isActive ) {
516- $icon . addClass ( "selected-button" ) ;
517- } else {
518- $icon . removeClass ( "selected-button" ) ;
519- }
520- }
521-
522515 /**
523516 * Escape HTML special characters
524517 */
@@ -541,13 +534,7 @@ define(function (require, exports, module) {
541534
542535 // Register commands
543536 CommandManager . register ( "New Terminal" , CMD_NEW_TERMINAL , _createNewTerminal ) ;
544- CommandManager . register ( "Toggle Terminal" , CMD_TOGGLE_TERMINAL , _togglePanel ) ;
545-
546- // Add menu item
547- const fileMenu = Menus . getMenu ( Menus . AppMenuBar . FILE_MENU ) ;
548- if ( fileMenu ) {
549- fileMenu . addMenuItem ( CMD_NEW_TERMINAL , null , Menus . AFTER , "file.close" ) ;
550- }
537+ CommandManager . register ( Strings . CMD_VIEW_TERMINAL , CMD_VIEW_TERMINAL , _showTerminal ) ;
551538
552539 // Initialize on app ready
553540 AppInit . appReady ( function ( ) {
@@ -558,12 +545,6 @@ define(function (require, exports, module) {
558545 _initNodeConnector ( ) ;
559546 _createPanel ( ) ;
560547
561- // Set up toolbar icon click handler
562- const $toolbarIcon = $ ( "#toolbar-terminal" ) ;
563- $toolbarIcon . html ( '<i class="fa-solid fa-terminal"></i>' ) ;
564- $toolbarIcon . removeClass ( "forced-hidden" ) ;
565- $toolbarIcon . on ( "click" , _togglePanel ) ;
566-
567548 // Detect shells
568549 ShellProfiles . init ( nodeConnector ) . then ( function ( ) {
569550 const shells = ShellProfiles . getShells ( ) ;
@@ -581,6 +562,6 @@ define(function (require, exports, module) {
581562 } ) ;
582563
583564 // Export for testing
584- exports . CMD_TOGGLE_TERMINAL = CMD_TOGGLE_TERMINAL ;
565+ exports . CMD_VIEW_TERMINAL = CMD_VIEW_TERMINAL ;
585566 exports . CMD_NEW_TERMINAL = CMD_NEW_TERMINAL ;
586567} ) ;
0 commit comments