@@ -15,11 +15,11 @@ import { ISettingRegistry } from '@jupyterlab/settingregistry';
1515import { ITerminal } from '@jupyterlab/terminal' ;
1616import { ITranslator , TranslationBundle } from '@jupyterlab/translation' ;
1717import { closeIcon , ContextMenuSvg } from '@jupyterlab/ui-components' ;
18- import { ArrayExt , toArray } from '@lumino/algorithm' ;
18+ import { ArrayExt , toArray , find } from '@lumino/algorithm' ;
1919import { CommandRegistry } from '@lumino/commands' ;
2020import { PromiseDelegate } from '@lumino/coreutils' ;
2121import { Message } from '@lumino/messaging' ;
22- import { ContextMenu , Menu , Panel , Widget } from '@lumino/widgets' ;
22+ import { ContextMenu , DockPanel , Menu , Panel , Widget } from '@lumino/widgets' ;
2323import * as React from 'react' ;
2424import { DiffModel } from './components/diff/model' ;
2525import { createPlainTextDiff } from './components/diff/PlainTextDiff' ;
@@ -50,6 +50,7 @@ import { discardAllChanges } from './widgets/discardAllChanges';
5050import { ManageRemoteDialogue } from './components/ManageRemoteDialogue' ;
5151import { CheckboxForm } from './widgets/GitResetToRemoteForm' ;
5252import { AdvancedPushForm } from './widgets/AdvancedPushForm' ;
53+ import { PreviewMainAreaWidget } from './components/diff/PreviewMainAreaWidget' ;
5354
5455export interface IGitCloneArgs {
5556 /**
@@ -87,6 +88,7 @@ interface IFileDiffArgument {
8788 filePath : string ;
8889 isText : boolean ;
8990 status ?: Git . Status ;
91+ isPreview ?: boolean ;
9092
9193 // when file has been relocated
9294 previousFilePath ?: string ;
@@ -528,9 +530,10 @@ export function addCommands(
528530 label : trans . __ ( 'Show Diff' ) ,
529531 caption : trans . __ ( 'Display a file diff.' ) ,
530532 execute : async args => {
531- const { model, isText } = args as any as {
533+ const { model, isText, isPreview } = args as any as {
532534 model : Git . Diff . IModel ;
533535 isText ?: boolean ;
536+ isPreview ?: boolean ;
534537 } ;
535538
536539 const fullPath = PathExt . join (
@@ -556,9 +559,10 @@ export function addCommands(
556559 if ( ! mainAreaItem ) {
557560 const content = new Panel ( ) ;
558561 const modelIsLoading = new PromiseDelegate < void > ( ) ;
559- const diffWidget = ( mainAreaItem = new MainAreaWidget < Panel > ( {
562+ const diffWidget = ( mainAreaItem = new PreviewMainAreaWidget < Panel > ( {
560563 content,
561- reveal : modelIsLoading . promise
564+ reveal : modelIsLoading . promise ,
565+ isPreview
562566 } ) ) ;
563567 diffWidget . id = id ;
564568 diffWidget . title . label = PathExt . basename ( model . filename ) ;
@@ -571,6 +575,19 @@ export function addCommands(
571575 shell . add ( diffWidget , 'main' ) ;
572576 shell . activateById ( diffWidget . id ) ;
573577
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+
574591 // Create the diff widget
575592 try {
576593 const widget = await buildDiffWidget (
@@ -855,7 +872,14 @@ export function addCommands(
855872 execute : async args => {
856873 const { files } = args as any as CommandArguments . IGitFileDiff ;
857874 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 ;
859883
860884 // nothing to compare to for untracked files
861885 if ( status === 'untracked' ) {
@@ -967,7 +991,8 @@ export function addCommands(
967991
968992 const widget = await commands . execute ( CommandIDs . gitShowDiff , {
969993 model,
970- isText
994+ isText,
995+ isPreview
971996 } as any ) ;
972997
973998 if ( widget ) {
0 commit comments