-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
Description
Bad:
this.addCommand({
id: 'open-sample-modal-complex',
name: 'Open sample modal (complex)',
callback: () => {
// Conditions to check
const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (!markdownView) {
new Notice('Please open a MarkdownView');
return;
}
new SampleModal(this.app).open();
}
});
Good:
this.addCommand({
id: 'open-sample-modal-complex',
name: 'Open sample modal (complex)',
checkCallback: (checking: boolean) => {
// Conditions to check
const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (markdownView) {
// If checking is true, we're simply "checking" if the command can be run.
// If checking is false, then we want to actually perform the operation.
if (!checking) {
new SampleModal(this.app).open();
}
// This command will only show up in Command Palette when the check function returns true
return true;
}
}
});