@@ -15,11 +15,11 @@ import { ISettingRegistry } from '@jupyterlab/settingregistry';
15
15
import { ITerminal } from '@jupyterlab/terminal' ;
16
16
import { ITranslator , TranslationBundle } from '@jupyterlab/translation' ;
17
17
import { closeIcon , ContextMenuSvg } from '@jupyterlab/ui-components' ;
18
- import { ArrayExt , toArray } from '@lumino/algorithm' ;
18
+ import { ArrayExt , toArray , find } from '@lumino/algorithm' ;
19
19
import { CommandRegistry } from '@lumino/commands' ;
20
20
import { PromiseDelegate } from '@lumino/coreutils' ;
21
21
import { Message } from '@lumino/messaging' ;
22
- import { ContextMenu , Menu , Panel , Widget } from '@lumino/widgets' ;
22
+ import { ContextMenu , DockPanel , Menu , Panel , Widget } from '@lumino/widgets' ;
23
23
import * as React from 'react' ;
24
24
import { DiffModel } from './components/diff/model' ;
25
25
import { createPlainTextDiff } from './components/diff/PlainTextDiff' ;
@@ -50,6 +50,7 @@ import { discardAllChanges } from './widgets/discardAllChanges';
50
50
import { ManageRemoteDialogue } from './components/ManageRemoteDialogue' ;
51
51
import { CheckboxForm } from './widgets/GitResetToRemoteForm' ;
52
52
import { AdvancedPushForm } from './widgets/AdvancedPushForm' ;
53
+ import { PreviewMainAreaWidget } from './components/diff/PreviewMainAreaWidget' ;
53
54
54
55
export interface IGitCloneArgs {
55
56
/**
@@ -87,6 +88,7 @@ interface IFileDiffArgument {
87
88
filePath : string ;
88
89
isText : boolean ;
89
90
status ?: Git . Status ;
91
+ isPreview ?: boolean ;
90
92
91
93
// when file has been relocated
92
94
previousFilePath ?: string ;
@@ -528,9 +530,10 @@ export function addCommands(
528
530
label : trans . __ ( 'Show Diff' ) ,
529
531
caption : trans . __ ( 'Display a file diff.' ) ,
530
532
execute : async args => {
531
- const { model, isText } = args as any as {
533
+ const { model, isText, isPreview } = args as any as {
532
534
model : Git . Diff . IModel ;
533
535
isText ?: boolean ;
536
+ isPreview ?: boolean ;
534
537
} ;
535
538
536
539
const fullPath = PathExt . join (
@@ -556,9 +559,10 @@ export function addCommands(
556
559
if ( ! mainAreaItem ) {
557
560
const content = new Panel ( ) ;
558
561
const modelIsLoading = new PromiseDelegate < void > ( ) ;
559
- const diffWidget = ( mainAreaItem = new MainAreaWidget < Panel > ( {
562
+ const diffWidget = ( mainAreaItem = new PreviewMainAreaWidget < Panel > ( {
560
563
content,
561
- reveal : modelIsLoading . promise
564
+ reveal : modelIsLoading . promise ,
565
+ isPreview
562
566
} ) ) ;
563
567
diffWidget . id = id ;
564
568
diffWidget . title . label = PathExt . basename ( model . filename ) ;
@@ -571,6 +575,19 @@ export function addCommands(
571
575
shell . add ( diffWidget , 'main' ) ;
572
576
shell . activateById ( diffWidget . id ) ;
573
577
578
+ // Search for the tab
579
+ const dockPanel = ( app . shell as any ) . _dockPanel as DockPanel ;
580
+
581
+ // Get the index of the most recent tab opened
582
+ let tabPosition = - 1 ;
583
+ const tabBar = find ( dockPanel . tabBars ( ) , bar => {
584
+ tabPosition = bar . titles . indexOf ( diffWidget . title ) ;
585
+ return tabPosition !== - 1 ;
586
+ } ) ;
587
+
588
+ // Pin the preview screen if applicable
589
+ PreviewMainAreaWidget . pinWidget ( tabPosition , tabBar , diffWidget ) ;
590
+
574
591
// Create the diff widget
575
592
try {
576
593
const widget = await buildDiffWidget (
@@ -855,7 +872,14 @@ export function addCommands(
855
872
execute : async args => {
856
873
const { files } = args as any as CommandArguments . IGitFileDiff ;
857
874
for ( const file of files ) {
858
- const { context, filePath, previousFilePath, isText, status } = file ;
875
+ const {
876
+ context,
877
+ filePath,
878
+ previousFilePath,
879
+ isText,
880
+ status,
881
+ isPreview
882
+ } = file ;
859
883
860
884
// nothing to compare to for untracked files
861
885
if ( status === 'untracked' ) {
@@ -967,7 +991,8 @@ export function addCommands(
967
991
968
992
const widget = await commands . execute ( CommandIDs . gitShowDiff , {
969
993
model,
970
- isText
994
+ isText,
995
+ isPreview
971
996
} as any ) ;
972
997
973
998
if ( widget ) {
0 commit comments