Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Template insertion support for Canvas cards #1522

Open
greetclammy opened this issue Jan 9, 2025 · 1 comment
Open

FR: Template insertion support for Canvas cards #1522

greetclammy opened this issue Jan 9, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@greetclammy
Copy link

Is your feature request related to a problem?
Cannot insert templates into Canvas cards due to "Templater error: No active editor" error. Forces creation of separate notes just to use templates within Canvas, unnecessarily cluttering vault.

Describe the solution you'd like
Add proper editor detection for Canvas cards, allowing direct template insertion similar to regular notes. Should seamlessly work when selecting a card and triggering a template.

Describe alternatives you've considered
Current workaround: Create temporary note → run template → copy content → paste into Canvas card → delete temporary note. Inefficient and disrupts workflow.

Additional context
Canvas cards use different editor instances than markdown notes. Integration would require detecting these specialized editor instances. Critical feature for users who heavily utilize Canvas in their workflow.

@zhao414
Copy link

zhao414 commented Feb 8, 2025

I am facing the same problem and looking at this issue.

Here is the clue that I have figured out so far.

In Templater.ts, append_template_to_active_file, the error message is triggered by:

        if (!active_editor || !active_editor.file || !active_editor.editor) {
            log_error(
                new TemplaterError("No active editor, can't append templates.")
            );
            return;

The problem is that in the canvas, when edit text in the node, the active-editor does not have a active-editor.file porperty. Instead, it has a unique (this is my guess) porperty named active-editor.node, which I think can be used to identity whether the current active-editor is a canvas node.

TODO:

  1. try the detection principle mentioned above, to see if it works
  2. After doing this detection, one can try the rest code in the append_template_to_active_file, to see whether they can work for canvas node. My guess is some modification is needed to adopt the "node" type, as for node, every operation will use functions looks like node.xxxx and the canvas may need to be re-rendered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants