Skip to content

Commit 7e11dfb

Browse files
committed
fix: hookSaveCommands not working after updating Obsidian
1 parent ce03887 commit 7e11dfb

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/main.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class PrettierPlugin extends Plugin {
1616
private formatter!: Formatter;
1717
private lastActiveFile: TFile | null = null;
1818
private events: EventRef[] = [];
19-
private originalSaveCallback: Command["callback"];
19+
private originalSaveCallback: Command["checkCallback"];
2020

2121
override async onload() {
2222
await this.loadSettings();
@@ -118,27 +118,27 @@ export default class PrettierPlugin extends Plugin {
118118

119119
private hookSaveCommands() {
120120
const saveCommand = this.app.commands.commands["editor:save-file"];
121-
const saveCallback = saveCommand?.callback;
121+
const saveCallback = saveCommand?.checkCallback;
122122
if (!saveCommand || !saveCallback) return;
123123

124124
this.originalSaveCallback = saveCallback;
125-
saveCommand.callback = async () => {
125+
saveCommand.checkCallback = checking => {
126+
if (checking) return saveCallback(checking);
127+
126128
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
127129
if (view) {
128-
await this.withPerformanceNotice(() =>
129-
this.formatter.formatOnSave(view.editor, view.file),
130-
);
130+
withPerfNotice(() => this.formatter.formatOnSave(view.editor, view.file));
131131
}
132132

133-
await saveCallback();
133+
saveCallback(checking);
134134
};
135135
}
136136

137137
private unhookSaveCommands() {
138138
const saveCommand = this.app.commands.commands["editor:save-file"];
139139
if (!saveCommand || !this.originalSaveCallback) return;
140140

141-
saveCommand.callback = this.originalSaveCallback;
141+
saveCommand.checkCallback = this.originalSaveCallback;
142142
}
143143

144144
private registerMenu() {

0 commit comments

Comments
 (0)