1- import  {  ICellModel  }  from  '@jupyterlab/cells' ; 
1+ import  {  Cell  }  from  '@jupyterlab/cells' ; 
22import  {  checkIcon ,  ToolbarButton ,  undoIcon  }  from  '@jupyterlab/ui-components' ; 
33import  {  ICellFooterTracker  }  from  'jupyterlab-cell-input-footer' ; 
44import  { 
@@ -12,9 +12,9 @@ import type { ISharedText } from '@jupyter/ydoc';
1212 */ 
1313export  interface  IUnifiedCellDiffOptions  extends  IBaseUnifiedDiffOptions  { 
1414  /** 
15-    * The cell to show the diff for 
15+    * The cell widget  to show the diff for 
1616   */ 
17-   cell : ICellModel ; 
17+   cell : Cell ; 
1818
1919  /** 
2020   * The cell footer tracker 
@@ -36,11 +36,72 @@ export class UnifiedCellDiffManager extends BaseUnifiedDiffManager {
3636    this . activate ( ) ; 
3737  } 
3838
39+   private  static  _activeDiffCount  =  0 ; 
40+ 
3941  /** 
4042   * Get the shared model for source manipulation 
4143   */ 
4244  protected  getSharedModel ( ) : ISharedText  { 
43-     return  this . _cell . sharedModel ; 
45+     return  this . _cell . model . sharedModel ; 
46+   } 
47+ 
48+   /** 
49+    * Activate the diff view without cell toolbar. 
50+    */ 
51+   protected  activate ( ) : void { 
52+     super . activate ( ) ; 
53+     UnifiedCellDiffManager . _activeDiffCount ++ ; 
54+ 
55+     const  observer  =  new  MutationObserver ( ( )  =>  { 
56+       this . hideCellToolbar ( ) ; 
57+     } ) ; 
58+ 
59+     observer . observe ( this . _cell . node ,  { 
60+       childList : true , 
61+       subtree : true 
62+     } ) ; 
63+ 
64+     ( this  as  any ) . _toolbarObserver  =  observer ; 
65+   } 
66+ 
67+   /** 
68+    * Deactivate the diff view with cell toolbar. 
69+    */ 
70+   protected  _deactivate ( ) : void { 
71+     super [ '_deactivate' ] ( ) ; 
72+     UnifiedCellDiffManager . _activeDiffCount  =  Math . max ( 
73+       0 , 
74+       UnifiedCellDiffManager . _activeDiffCount  -  1 
75+     ) ; 
76+ 
77+     const  observer  =  ( this  as  any ) . _toolbarObserver  as  MutationObserver ; 
78+     if  ( observer )  { 
79+       observer . disconnect ( ) ; 
80+     } 
81+   } 
82+   /** 
83+    * Hide the cell's toolbar while the diff is active 
84+    */ 
85+   protected  hideCellToolbar ( ) : void { 
86+     const  toolbar  =  this . _cell . node . querySelector ( 'jp-toolbar' )  as  HTMLElement ; 
87+     if  ( toolbar )  { 
88+       toolbar . style . display  =  'none' ; 
89+     } 
90+   } 
91+ 
92+   /** 
93+    * Show the cell's toolbar when the diff is deactivated 
94+    */ 
95+   protected  showCellToolbar ( ) : void { 
96+     if  ( UnifiedCellDiffManager . _activeDiffCount  >  0 )  { 
97+       return ; 
98+     } 
99+     const  toolbar  =  this . _cell . node . querySelector ( 
100+       'jp-toolbar' 
101+     )  as  HTMLElement  |  null ; 
102+     if  ( toolbar )  { 
103+       toolbar . style . display  =  '' ; 
104+     } 
44105  } 
45106
46107  /** 
@@ -81,6 +142,9 @@ export class UnifiedCellDiffManager extends BaseUnifiedDiffManager {
81142    } 
82143
83144    this . _cellFooterTracker . showFooter ( cellId ) ; 
145+ 
146+     // Hide the main cell toolbar to avoid overlap 
147+     this . hideCellToolbar ( ) ; 
84148  } 
85149
86150  /** 
@@ -104,9 +168,12 @@ export class UnifiedCellDiffManager extends BaseUnifiedDiffManager {
104168
105169    // Hide the footer if no other items remain 
106170    this . _cellFooterTracker . hideFooter ( cellId ) ; 
171+ 
172+     // Show the main cell toolbar again 
173+     this . showCellToolbar ( ) ; 
107174  } 
108175
109-   private  _cell : ICellModel ; 
176+   private  _cell : Cell ; 
110177  private  _cellFooterTracker ?: ICellFooterTracker ; 
111178} 
112179
0 commit comments