@@ -19,7 +19,6 @@ import {
1919  UnifiedFileDiffManager 
2020}  from  './diff/unified-file' ; 
2121import  {  CodeMirrorEditor  }  from  '@jupyterlab/codemirror' ; 
22- import  {  ToolbarButton  }  from  '@jupyterlab/ui-components' ; 
2322
2423/** 
2524 * The translation namespace for the plugin. 
@@ -314,54 +313,62 @@ const unifiedCellDiffPlugin: JupyterFrontEndPlugin<void> = {
314313    notebookTracker . widgetAdded . connect ( ( sender ,  notebookPanel )  =>  { 
315314      const  notebookId  =  notebookPanel . id ; 
316315
317-       let  acceptAllButton : ToolbarButton  |  null  =  null ; 
318-       let  rejectAllButton : ToolbarButton  |  null  =  null ; 
316+       let  floatingPanel : HTMLElement  |  null  =  null ; 
319317
320-       function  updateToolbar ( )  { 
321-         const  managers  =  getNotebookManagers ( notebookId ) ; 
318+       function  createFloatingPanel ( ) : HTMLElement  { 
319+         const  panel  =  document . createElement ( 'div' ) ; 
320+         panel . classList . add ( 'jp-unified-diff-floating-panel' ) ; 
321+ 
322+         const  acceptButton  =  document . createElement ( 'button' ) ; 
323+         acceptButton . classList . add ( 'jp-merge-accept-button' ) ; 
324+         acceptButton . textContent  =  'Accept All' ; 
325+         acceptButton . title  =  trans . __ ( 'Accept all changes in this notebook' ) ; 
326+         acceptButton . onclick  =  ( )  =>  { 
327+           getNotebookManagers ( notebookId ) . forEach ( m  =>  m . acceptAll ( ) ) ; 
328+           updateFloatingPanel ( ) ; 
329+         } ; 
330+ 
331+         const  rejectButton  =  document . createElement ( 'button' ) ; 
332+         rejectButton . classList . add ( 'jp-merge-reject-button' ) ; 
333+         rejectButton . textContent  =  'Reject All' ; 
334+         rejectButton . title  =  trans . __ ( 'Reject all changes in this notebook' ) ; 
335+         rejectButton . onclick  =  ( )  =>  { 
336+           getNotebookManagers ( notebookId ) . forEach ( m  =>  m . rejectAll ( ) ) ; 
337+           updateFloatingPanel ( ) ; 
338+         } ; 
339+ 
340+         panel . appendChild ( acceptButton ) ; 
341+         panel . appendChild ( rejectButton ) ; 
342+         return  panel ; 
343+       } 
322344
345+       function  updateFloatingPanel ( ) : void { 
346+         const  managers  =  getNotebookManagers ( notebookId ) ; 
323347        const  anyPending  =  managers . some ( m  =>  m . hasPendingChanges ( ) ) ; 
348+ 
324349        if  ( ! anyPending )  { 
325-           if  ( acceptAllButton )  { 
326-             acceptAllButton . dispose ( ) ; 
327-           } 
328-           if  ( rejectAllButton )  { 
329-             rejectAllButton . dispose ( ) ; 
350+           if  ( floatingPanel  &&  floatingPanel . parentElement )  { 
351+             floatingPanel . parentElement . removeChild ( floatingPanel ) ; 
330352          } 
331-           acceptAllButton  =  null ; 
332-           rejectAllButton  =  null ; 
353+           floatingPanel  =  null ; 
333354          return ; 
334355        } 
335356
336-         if  ( ! acceptAllButton )  { 
337-           acceptAllButton  =  new  ToolbarButton ( { 
338-             label : trans . __ ( 'Accept All' ) , 
339-             className : 'accept-all-changes' , 
340-             tooltip : trans . __ ( 'Accept all changes in this notebook' ) , 
341-             onClick : ( )  =>  { 
342-               getNotebookManagers ( notebookId ) . forEach ( m  =>  m . acceptAll ( ) ) ; 
343-               updateToolbar ( ) ; 
344-             } 
345-           } ) ; 
346-           notebookPanel . toolbar . addItem ( 'accept-all-changes' ,  acceptAllButton ) ; 
357+         if  ( ! floatingPanel )  { 
358+           floatingPanel  =  createFloatingPanel ( ) ; 
359+           notebookPanel . node . appendChild ( floatingPanel ) ; 
347360        } 
361+       } 
348362
349-         if  ( ! rejectAllButton )  { 
350-           rejectAllButton  =  new  ToolbarButton ( { 
351-             label : trans . __ ( 'Reject All' ) , 
352-             className : 'reject-all-changes' , 
353-             tooltip : trans . __ ( 'Reject all changes in this notebook' ) , 
354-             onClick : ( )  =>  { 
355-               getNotebookManagers ( notebookId ) . forEach ( m  =>  m . rejectAll ( ) ) ; 
356-               updateToolbar ( ) ; 
357-             } 
358-           } ) ; 
359-           notebookPanel . toolbar . addItem ( 'reject-all-changes' ,  rejectAllButton ) ; 
363+       notebookPanel . disposed . connect ( ( )  =>  { 
364+         clearNotebookManagers ( notebookId ) ; 
365+         if  ( floatingPanel  &&  floatingPanel . parentElement )  { 
366+           floatingPanel . parentElement . removeChild ( floatingPanel ) ; 
360367        } 
361-       } 
368+         floatingPanel  =  null ; 
369+       } ) ; 
362370
363-       notebookPanel . disposed . connect ( ( )  =>  clearNotebookManagers ( notebookId ) ) ; 
364-       notebookPanel . node . addEventListener ( 'diff-updated' ,  updateToolbar ) ; 
371+       notebookPanel . node . addEventListener ( 'diff-updated' ,  updateFloatingPanel ) ; 
365372
366373      const  originalRegister  =  registerCellManager ; 
367374      registerCellManager  =  ( nid : string ,  manager : UnifiedCellDiffManager )  =>  { 
0 commit comments