gpt4 book ai didi

node.js - 在 Electron BrowserWindow 中进行全文搜索

转载 作者:搜寻专家 更新时间:2023-10-31 23:31:31 24 4
gpt4 key购买 nike

Electron应用程序框架有内置的文本搜索吗?

quick-start application不提供任何明显的搜索功能(例如使用 Ctrl-F 或从菜单选项)。我原以为这是一个 BrowserWindow选项(或其 WebContents 的一个选项),但我在文档中看不到任何有用的信息。

最佳答案

我知道这是一个旧线程,但可能仍然与那里的人相关。有同样的问题,首先使用 electron-in-page-search 修复,但此组件无法与 Electron 2 或更高版本一起正常工作。

然后终于找到electron-find解决了我的问题。与 Electron 4 一起使用。

您只需将组件添加到您的项目中:

npm install electron-find --save

在您的 Electron 主进程中添加一个全局快捷方式,以通过 ctrl+f 将事件发送到渲染器:

globalShortcut.register('CommandOrControl+F', () => {
window.webContents.send('on-find');
});

然后你可以将它添加到你的页面(渲染进程)

const remote = require('electron').remote;
const FindInPage = require('electron-find').FindInPage;

let findInPage = new FindInPage(remote.getCurrentWebContents());

ipcRenderer.on('on-find', (e, args) => {
findInPage.openFindWindow()
})

希望对您有所帮助。

关于node.js - 在 Electron BrowserWindow 中进行全文搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33837760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com