Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions schema/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@
},
"additionalProperties": false,
"type": "object"
},
"formatOnSave": {
"additionalProperties": false,
"type": "boolean"
}
},
"properties": {
Expand Down Expand Up @@ -291,6 +295,12 @@
"description": "Config to be passed into styler's style_text function call.",
"$ref": "#/definitions/styler",
"default": {}
},
"formatOnSave": {
"title": "Auto format config",
"description": "Auto format code when save the notebook.",
"$ref": "#/definitions/formatOnSave",
"default": false
}
},
"additionalProperties": false,
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,20 @@ class JupyterLabCodeFormatter
this.app.commands.label(Constants.FORMAT_ALL_COMMAND),
button
);

context.saveState.connect(this.onSave, this);

return new DisposableDelegate(() => {
button.dispose();
});
}

private async onSave(context: DocumentRegistry.IContext<INotebookModel>, state: DocumentRegistry.SaveState) {
if (state == 'started' && this.config.formatOnSave) {
await this.notebookCodeFormatter.formatAllCodeCells(this.config);
}
}

private setupWidgetExtension() {
this.app.docRegistry.addWidgetExtension('Notebook', this);
}
Expand Down