electron-findbar 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +6 -5
  2. package/index.js +9 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  ## Installation
15
15
 
16
- Install the `electron-findbar` package via npm:
16
+ Install the `electron-findbar` package via [npm](https://www.npmjs.com/package/electron-findbar):
17
17
 
18
18
  ```sh
19
19
  npm install electron-findbar
@@ -21,7 +21,7 @@ npm install electron-findbar
21
21
 
22
22
  ## Overview
23
23
 
24
- The `electron-findbar` is a `BrowserWindow` component designed to emulate the Chrome findbar layout, leveraging the `webContents.findInPage` method to navigate through matches. Inter-process communication (IPC) is used for interaction between the `main` and `renderer` processes.
24
+ The `electron-findbar` package creates a `BrowserWindow`-based component designed to emulate the Chrome findbar layout, leveraging the `webContents.findInPage` method to navigate through matches. Inter-process communication (IPC) is used for interaction between the `main` and `renderer` processes.
25
25
 
26
26
  ### Memory Usage
27
27
 
@@ -55,14 +55,14 @@ Alternatively, you can provide a custom `WebContents` as the second parameter. I
55
55
  const findbar = Findbar.from(baseWindow, webContents)
56
56
  ```
57
57
 
58
- Is also possible to create a findbar providing only the web contents. The BaseWindow.getAllWindows() will be used to query for the parent window:
58
+ It is also possible to create a findbar providing only the web contents. The BaseWindow.getAllWindows() will be used to query for the parent window:
59
59
 
60
60
  ```js
61
61
  // Create or retrieve the findbar associated to the webContents.
62
62
  const findbar = Findbar.from(webContents)
63
63
  ```
64
64
 
65
- **Note:** The findbar is ALWAYS linked to the webContents not the window. The parent is only the window to connect the events and stay on top. If the `.from(webContents)` is used to retrieve an existing findbar previously created with a parent, the findbar will stay connected to the parent.
65
+ **Note:** The findbar is ALWAYS linked to the webContents, not the window. The parent is only the window to connect the events and stay on top. If the `.from(webContents)` is used to retrieve an existing findbar previously created with a parent, the findbar will stay connected to the parent.
66
66
 
67
67
  #### Retrieve if exists
68
68
 
@@ -305,10 +305,11 @@ If the `contextIsolation` is enabled, the `electron-findbar/remote` will not be
305
305
  ```js
306
306
  const $remote = (ipc => ({
307
307
  getLastState: async () => ipc.invoke('electron-findbar/last-state'),
308
- inputChange: (value) => { ipc.send('electron-findbar/input-change', value) },
308
+ inputChange: (text) => { ipc.send('electron-findbar/input-change', text) },
309
309
  matchCase: (value) => { ipc.send('electron-findbar/match-case', value) },
310
310
  previous: () => { ipc.send('electron-findbar/previous') },
311
311
  next: () => { ipc.send('electron-findbar/next') },
312
+ open: () => { ipc.send('electron-findbar/open') },
312
313
  close: () => { ipc.send('electron-findbar/close') }
313
314
  })) (require('electron').ipcRenderer)
314
315
 
package/index.js CHANGED
@@ -14,7 +14,7 @@ class Findbar {
14
14
  #findableContents
15
15
 
16
16
  /** @type { { active: number, total: number } } */
17
- #matches
17
+ #matches = { active: 0, total: 0 }
18
18
 
19
19
  /** @type {(findbarWindow: BrowserWindow) => void} */
20
20
  #windowHandler
@@ -171,6 +171,7 @@ class Findbar {
171
171
  * @returns {void}
172
172
  */
173
173
  findPrevious() {
174
+ if (this.#matches.total < 2) { return }
174
175
  this.#matches.active === 1 && (this.#fixMove = false)
175
176
  this.isOpen() && this.#findInContent({ forward: false })
176
177
  }
@@ -180,6 +181,7 @@ class Findbar {
180
181
  * @returns {void}
181
182
  */
182
183
  findNext() {
184
+ if (this.#matches.total < 2) { return }
183
185
  this.#matches.active === this.#matches.total && (this.#fixMove = true)
184
186
  this.isOpen() && this.#findInContent({ forward: true })
185
187
  }
@@ -346,7 +348,8 @@ class Findbar {
346
348
  this.#fixMove = null
347
349
  }
348
350
 
349
- this.#matches = { active, total }
351
+ this.#matches.active = active
352
+ this.#matches.total = total
350
353
 
351
354
  this.#window.webContents.send('electron-findbar/matches', this.#matches)
352
355
  }
@@ -365,16 +368,16 @@ class Findbar {
365
368
  * @returns {WebContents | undefined} The web contents if any.
366
369
  */
367
370
  static #retrieveWebContents(window) {
368
- return window.webContents ?? window.contentView?.children[0]
371
+ return window.webContents ?? window.contentView?.children[0]?.webContents
369
372
  }
370
373
 
371
374
  /**
372
375
  * Get the parent window from web contents.
373
- * @param {WebContents} cont
376
+ * @param {WebContents} w
374
377
  * @returns {BaseWindow | undefined} Parent window if any.
375
378
  */
376
- static #getBaseWindowFromWebContents(cont) {
377
- return BaseWindow.getAllWindows().find(win => win.webContents === cont || win.contentView.children.some(child => child.webContents === cont))
379
+ static #getBaseWindowFromWebContents(w) {
380
+ return BaseWindow.getAllWindows().find(win => win.webContents === w || win.contentView.children.some(child => child.webContents === w))
378
381
  }
379
382
 
380
383
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-findbar",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "Chrome-like findbar for your Electron app.",
5
5
  "main": "index.js",
6
6
  "files": [