@@ -25,7 +25,8 @@ import {
25
25
isOSX ,
26
26
SelectionService ,
27
27
Emitter ,
28
- Event
28
+ Event ,
29
+ ViewColumn
29
30
} from '@theia/core/lib/common' ;
30
31
import {
31
32
ApplicationShell , KeybindingContribution , KeyCode , Key , WidgetManager ,
@@ -36,7 +37,7 @@ import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/li
36
37
import { TERMINAL_WIDGET_FACTORY_ID , TerminalWidgetFactoryOptions , TerminalWidgetImpl } from './terminal-widget-impl' ;
37
38
import { TerminalKeybindingContexts } from './terminal-keybinding-contexts' ;
38
39
import { TerminalService } from './base/terminal-service' ;
39
- import { TerminalWidgetOptions , TerminalWidget } from './base/terminal-widget' ;
40
+ import { TerminalWidgetOptions , TerminalWidget , TerminalLocation } from './base/terminal-widget' ;
40
41
import { UriAwareCommandHandler } from '@theia/core/lib/common/uri-command-handler' ;
41
42
import { ShellTerminalServerProxy } from '../common/shell-terminal-protocol' ;
42
43
import URI from '@theia/core/lib/common/uri' ;
@@ -644,20 +645,46 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
644
645
645
646
// TODO: reuse WidgetOpenHandler.open
646
647
open ( widget : TerminalWidget , options ?: WidgetOpenerOptions ) : void {
648
+ const area = widget . location === TerminalLocation . Editor ? 'main' : 'bottom' ;
649
+ const widgetOptions : ApplicationShell . WidgetOptions = { area : area , ...options ?. widgetOptions } ;
650
+ let preserveFocus = false ;
651
+
652
+ if ( typeof widget . location === 'object' ) {
653
+ if ( 'parentTerminal' in widget . location ) {
654
+ widgetOptions . ref = this . getById ( widget . location . parentTerminal ) ;
655
+ widgetOptions . mode = 'split-right' ;
656
+ } else if ( 'viewColumn' in widget . location ) {
657
+ preserveFocus = widget . location . preserveFocus ?? false ;
658
+ switch ( widget . location . viewColumn ) {
659
+ case ViewColumn . Active :
660
+ widgetOptions . ref = this . shell . currentWidget ;
661
+ widgetOptions . mode = 'tab-after' ;
662
+ break ;
663
+ case ViewColumn . Beside :
664
+ widgetOptions . ref = this . shell . currentWidget ;
665
+ widgetOptions . mode = 'split-right' ;
666
+ break ;
667
+ default :
668
+ widgetOptions . area = 'main' ;
669
+ const mainAreaTerminals = this . shell . getWidgets ( 'main' ) . filter ( w => w instanceof TerminalWidget && w . isVisible ) ;
670
+ const column = Math . min ( widget . location . viewColumn , mainAreaTerminals . length ) ;
671
+ widgetOptions . mode = widget . location . viewColumn <= mainAreaTerminals . length ? 'split-left' : 'split-right' ;
672
+ widgetOptions . ref = mainAreaTerminals [ column - 1 ] ;
673
+ }
674
+ }
675
+ }
676
+
647
677
const op : WidgetOpenerOptions = {
648
678
mode : 'activate' ,
649
679
...options ,
650
- widgetOptions : {
651
- area : 'bottom' ,
652
- ...( options && options . widgetOptions )
653
- }
680
+ widgetOptions : widgetOptions
654
681
} ;
655
682
if ( ! widget . isAttached ) {
656
683
this . shell . addWidget ( widget , op . widgetOptions ) ;
657
684
}
658
- if ( op . mode === 'activate' ) {
685
+ if ( op . mode === 'activate' && ! preserveFocus ) {
659
686
this . shell . activateWidget ( widget . id ) ;
660
- } else if ( op . mode === 'reveal' ) {
687
+ } else if ( op . mode === 'reveal' || preserveFocus ) {
661
688
this . shell . revealWidget ( widget . id ) ;
662
689
}
663
690
}
0 commit comments