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
23 changes: 13 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class LinterPlugin extends Plugin {
private overridePaste: boolean = false;
private hasCustomCommands: boolean = false;
private customCommandsLock = new AsyncLock();
private originalSaveCallback?: () => void = null;
private originalSaveCallback?: (checking: boolean) => boolean | void = null;
// The amount of files you can use editor lint on at once is pretty small, so we will use an array
private editorLintFiles: TFile[] = [];
// the amount of files that can be linted as a file can be quite large, so we will want to use a set to make
Expand Down Expand Up @@ -322,15 +322,18 @@ export default class LinterPlugin extends Plugin {
this.originalSaveCallback = saveCommandDefinition?.checkCallback;

if (typeof this.originalSaveCallback === 'function') {
saveCommandDefinition.checkCallback = () => {
this.originalSaveCallback();

if (this.settings.lintOnSave && this.isEnabled) {
const editor = this.getEditor();
if (editor) {
const file = this.app.workspace.getActiveFile();
if (!this.shouldIgnoreFile(file) && this.isMarkdownFile(file) && editor.cm) {
void this.runLinterEditor(editor);
saveCommandDefinition.checkCallback = (checking: boolean) => {
if (checking) {
return this.originalSaveCallback(checking);
} else {
this.originalSaveCallback(checking);
if (this.settings.lintOnSave && this.isEnabled) {
const editor = this.getEditor();
if (editor) {
const file = this.app.workspace.getActiveFile();
if (!this.shouldIgnoreFile(file) && this.isMarkdownFile(file) && editor.cm) {
void this.runLinterEditor(editor);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/typings/obsidian-ex.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface ObsidianCommandInterface {
executeCommandById(id: string): void;
commands: {
'editor:save-file': {
checkCallback(): void;
checkCallback(checking: boolean): boolean | void;
};
};
listCommands(): Command[];
Expand Down