思源事件原理

思源把插件名称生成注释dom结点,然后把相关事件绑定其上,在需要触发的地方通过遍历所有插件,调用emit进行触发。

see https://github.com/siyuan-note/siyuan/blob/0b0c27b0bad3e2a073f61ed28c6ce76d2f2b4b07/app/src/plugin/EventBus.ts#L7

示例:

see https://ld246.com/article/1742362626760/comment/1742522667361?r=wilsons#comments

input-search​事件为例

其实就是#searchInput 元素的 dom 事件

local-searchdata​ 存储数据是在 blur 时

input-search​ 是在 input 时

参考源码 https://github.com/siyuan-note/siyuan/blob/0b0c27b0bad3e2a073f61ed28c6ce76d2f2b4b07/app/src/search/util.ts#L912

另外,思源底部的注释原来是事件绑定结点。

https://github.com/siyuan-note/siyuan/blob/0b0c27b0bad3e2a073f61ed28c6ce76d2f2b4b07/app/src/plugin/EventBus.ts#L7

  1. 全局搜索, 默认搜索路径可以通过这个获取: window.siyuan.storage['local-searchdata'].idPath
  2. 搜索过程中, 修改了指定路径, 会触发思源的 input-search​ 事件
    事件回调参数(cfg)里面有路径: cfg.detail.config.idPath
    image.png

image.png

留下你的脚步
推荐阅读