Skip to content

[FR] Accept checkCallback/etc callback fns in invocable scripts #45

@garrett-is-a-swann

Description

@garrett-is-a-swann

Description

It'd be nice if invokable scripts accepted the various check-callbacks for addCommand, and passed them through when creating the command.

Details

  1. See: https://docs.obsidian.md/Reference/TypeScript+API/Command/editorCheckCallback + those it overrides for names for callbacks to be accepted.
  2. When parsing the scripts in the invocable scripts folder, check to see if these callbacks are exported.
  3. Pass them to the addCommand function if they exist.

Desired Behavior

See above

Current Behavior

Only the default callback is implemented.

Attachments

Possible codescript:

const { MarkdownView } = require('obsidian');

exports.checkCallback = (app) => (checking: boolean) => {
	const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
	if (markdownView) {
		if (!checking) {
			console.log('It worked!');
		}
		return true;
	}
}

And be used as:

plugin.addCommand({
  callback: /* ... larger-precedence-callbacks-nullable-chain ... */ checkCallback?.(app) ?? async () => {
    await invoke(plugin, join(invocableScriptsFolder, scriptFile));
  },
  id: `${COMMAND_NAME_PREFIX}${scriptFile}`,
  name: `Invoke Script: ${scriptFile}`
});

Edit: On second thought, I don't think you need to bother implementing the precedence here. addCallback will just handle it.

Confirmations

  • I attached a video showing the current behavior, or it is not necessary
  • I attached a sample vault where the desired Feature Request could be applied, or it is not necessary
  • I have tested the absence of the requested feature with the latest version of the plugin
  • I have checked GitHub for existing Feature Requests

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions