是的,float search可以参考帖子 如何在新窗口中打开ob自带的搜索面板? - #4,来自 wilson
不过这里只搜索指定文件可把调用改为 openSearch(`path:${app.workspace.getActiveFile()?.path} ${app.workspace.activeEditor?.getSelection()||""}`)
完整代码如下 (更改了函数名,添加了isInHover参数):
// 打开悬浮搜索
// query查询字符串,isInHover是否是用hover editor
async function openFloatSearch(query, isInHover=true) {
const selected = app.workspace.activeLeaf.view.editor?.getSelection();
const leaf = app.workspace.getLeaf('tab');
// 这种方式成功的话可以使用这种方式,不会先弹出tab,但有时会不成功
//const leaf = app.workspace.createLeafInParent(app.workspace.floatingSplit);
await leaf.setViewState({
type: 'search',
active: true,
state: {
query: query || selected || ""
}
});
if(isInHover) app.plugins.plugins['obsidian-hover-editor'].convertLeafToPopover(leaf);
}
openFloatSearch(`path:${app.workspace.getActiveFile()?.path} ${app.workspace.activeEditor?.getSelection()||""}`);