The ability to decorate/override the editor:save-file
command by modifying this.app.commands.commands[commandId].callback
has stopped working since Obsidian Desktop version 1.9.10.
This breaks existing plugins that rely on intercepting save operations (such as formaters).
Reproduction code
import { Plugin } from "obsidian";
export default class ExamplePlugin extends Plugin {
onload() {
const appCommands = this.app.commands?.commands;
const commandsToOverride = ["editor:save-file"];
if (!appCommands) {
console.log("No commands found in the app.");
return;
}
commandsToOverride.forEach((commandId) => {
const command = appCommands[commandId];
if (!command) {
console.log(`Command not found: ${commandId}`);
return;
}
console.log(`Overriding command: ${commandId}`);
// This assignment no longer has any effect in 1.9.10
command.callback = () => {
console.log(`Command executed: ${commandId}`);
// Custom logic here
};
});
}
}
Expected
- The
command.callback
assignment should override the original callback - When
editor:save-file
is executed (via Ctrl+S, auto-save, etc.), the custom callback should be invoked - This pattern worked in versions prior to 1.9.10
Actual
- The
command.callback
assignment appears to succeed (no errors) - However, the custom callback is never invoked
- The original save behavior continues to execute, ignoring the override
- Console logs from the custom callback do not appear