File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 226226            },
227227            "additionalProperties" : false ,
228228            "type" : " object" 
229+         },
230+         "formatOnSave" : {
231+             "additionalProperties" : false ,
232+             "type" : " boolean" 
229233        }
230234    },
231235    "properties" : {
291295            "description" : " Config to be passed into styler's style_text function call." 
292296            "$ref" : " #/definitions/styler" 
293297            "default" : {}
298+         },
299+         "formatOnSave" : {
300+             "title" : " Auto format config" 
301+             "description" : " Auto format code when save the notebook." 
302+             "$ref" : " #/definitions/formatOnSave" 
303+             "default" : false 
294304        }
295305    },
296306    "additionalProperties" : false ,
Original file line number Diff line number Diff line change @@ -96,11 +96,20 @@ class JupyterLabCodeFormatter
9696      this . app . commands . label ( Constants . FORMAT_ALL_COMMAND ) , 
9797      button 
9898    ) ; 
99+ 
100+     context . saveState . connect ( this . onSave ,  this ) ; 
101+ 
99102    return  new  DisposableDelegate ( ( )  =>  { 
100103      button . dispose ( ) ; 
101104    } ) ; 
102105  } 
103106
107+   private  async  onSave ( context : DocumentRegistry . IContext < INotebookModel > ,  state : DocumentRegistry . SaveState )  { 
108+     if  ( state  ==  'started'  &&  this . config . formatOnSave )  { 
109+       await  this . notebookCodeFormatter . formatAllCodeCells ( this . config ) ; 
110+     } 
111+   } 
112+ 
104113  private  setupWidgetExtension ( )  { 
105114    this . app . docRegistry . addWidgetExtension ( 'Notebook' ,  this ) ; 
106115  } 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments