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

Add parameter nodeElement to protyleSlash.callback #14036

Closed
frostime opened this issue Feb 9, 2025 · 0 comments
Closed

Add parameter nodeElement to protyleSlash.callback #14036

frostime opened this issue Feb 9, 2025 · 0 comments
Assignees
Milestone

Comments

@frostime
Copy link
Contributor

frostime commented Feb 9, 2025

In what scenarios do you need this feature?

目前 slash 命令的 callback 函数仅仅传入一个 protyle 对象。但是对 slash 而言更重要的是获取当前所在的块。

interface IPluginProtyleSlash {
    filter: string[];
    html: string;
    id: string;
    callback(protyle: Protyle): void;
}

目前我是通过绕路的方法,拿到当前所在的 node 节点

const selection = window.getSelection();
const focusNode: Node = selection?.focusNode;
if (!focusNode) {
    showMessage(`Failed, can't find focus node`, 5000, 'error');
    return;
}
let ele: HTMLElement = focusNode.nodeType === Node.TEXT_NODE ?
    focusNode.parentElement : focusNode as HTMLElement;
ele = ele.closest('[data-node-id]') as HTMLElement;

但是每次这么弄实在有些麻烦。希望可以增加传入的一些参数,能直接获取所在块的信息。

Describe the optimal solution

callback 添加参数,比如直接传入所在的 Node 节点的 HTMLElement(如果能额外传入 block 对象就更好了,不然还需要使用 async 函数查询对应的块)

Describe the candidate solution

No response

Other information

No response

@Vanessa219 Vanessa219 changed the title Plugin API | 为 Slash 命令回调函数传入所在 Node 的 element 对象。 Add parameter nodeElement to protyleSlash.callback Feb 11, 2025
Vanessa219 added a commit to siyuan-note/petal that referenced this issue Feb 11, 2025
Vanessa219 added a commit to siyuan-note/plugin-sample that referenced this issue Feb 11, 2025
@Vanessa219 Vanessa219 added this to the 3.1.22 milestone Feb 11, 2025
Vanessa219 added a commit that referenced this issue Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants