Electron BrowserWindow 中的全文搜索 [英] Full text search in Electron BrowserWindow

查看:16
本文介绍了Electron BrowserWindow 中的全文搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Electron 应用程序框架是否有内置文本搜索功能?

Does the Electron application framework have built-in text search?

快速启动应用程序不提供任何明显的搜索功能(例如使用Ctrl-F 或从菜单选项).我本来希望这是一个 BrowserWindow选项(或其 WebContents 的选项),但我在文档中看不到任何有用的信息.

The quick-start application doesn't provide any apparent search functionality (e.g. using Ctrl-F or from the menu options). I would have expected this to be a BrowserWindow option (or an option of its WebContents), but I don't see anything helpful in the docs.

推荐答案

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

I know this is an old thread, but might still be relevant for people out there. Had the same problem, and first fixed by using electron-in-page-search, but this component doesn't work properly with Electron 2 or greater.

然后终于发现 electron-find 解决了我的问题.与 Electron 4 一起使用.

Then finally found electron-find resolved my problem. Using with Electron 4.

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

You just add the component to your project:

npm install electron-find --save

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

Add a global shortcut in your Electron main process to send an event to the renderer in a ctrl+f:

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

然后您可以将其添加到您的页面(渲染器进程)

And then you can add this to your page (the renderer process)

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()
})

希望对您有所帮助.

这篇关于Electron BrowserWindow 中的全文搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆