electron-findbar 3.1.1 → 3.2.0
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.
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/index.js +33 -7
- package/package.json +1 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ It is also possible to create a findbar providing only the web contents. The Bas
|
|
|
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. If a different parent is used, the parent window is updated automatically.
|
|
66
66
|
|
|
67
67
|
#### Retrieve if exists
|
|
68
68
|
|
|
@@ -338,7 +338,7 @@ The `updateParentWindow` method allows you to change the parent window while pre
|
|
|
338
338
|
|
|
339
339
|
```javascript
|
|
340
340
|
// Create a findbar for the initial window
|
|
341
|
-
const findbar = Findbar.from(oldWindow, webContents)
|
|
341
|
+
const findbar = Findbar.from([oldWindow, ]webContents)
|
|
342
342
|
|
|
343
343
|
// Later, when you need to change the parent:
|
|
344
344
|
findbar.updateParentWindow(newWindow)
|
package/index.js
CHANGED
|
@@ -13,6 +13,9 @@ class Findbar {
|
|
|
13
13
|
/** @type {WebContents} */
|
|
14
14
|
#findableContents
|
|
15
15
|
|
|
16
|
+
/** @type {boolean} */
|
|
17
|
+
#propagateVisibilityEvents = true
|
|
18
|
+
|
|
16
19
|
/** @type { { active: number, total: number } } */
|
|
17
20
|
#matches = { active: 0, total: 0 }
|
|
18
21
|
|
|
@@ -63,9 +66,8 @@ class Findbar {
|
|
|
63
66
|
constructor (parent, webContents) {
|
|
64
67
|
if (isFindable(parent)) {
|
|
65
68
|
this.#findableContents = parent
|
|
66
|
-
|
|
69
|
+
parent = Findbar.#getBaseWindowFromWebContents(this.#findableContents)
|
|
67
70
|
} else {
|
|
68
|
-
this.#parent = parent
|
|
69
71
|
this.#findableContents = webContents ?? Findbar.#retrieveWebContents(parent)
|
|
70
72
|
}
|
|
71
73
|
|
|
@@ -76,6 +78,7 @@ class Findbar {
|
|
|
76
78
|
this.#findableContents._findbar = this
|
|
77
79
|
|
|
78
80
|
this.#findableContents.once('destroyed', () => { this.detach() })
|
|
81
|
+
this.updateParentWindow(parent)
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
/**
|
|
@@ -87,6 +90,7 @@ class Findbar {
|
|
|
87
90
|
this.#focusWindowAndHighlightInput()
|
|
88
91
|
return
|
|
89
92
|
}
|
|
93
|
+
if (!this.#parent) { this.updateParentWindow() }
|
|
90
94
|
const options = Findbar.#mergeStandardOptions(this.#customOptions, this.#parent)
|
|
91
95
|
this.#isMovable = options.movable
|
|
92
96
|
this.#window = new BrowserWindow(options)
|
|
@@ -127,6 +131,9 @@ class Findbar {
|
|
|
127
131
|
if (this.#parent === newParent) { return }
|
|
128
132
|
this.close()
|
|
129
133
|
this.#parent = newParent ?? Findbar.#getBaseWindowFromWebContents(this.#findableContents)
|
|
134
|
+
if (this.#parent && !this.#parent.isDestroyed()) {
|
|
135
|
+
this.#parent.once('closed', () => { this.#removeParent() })
|
|
136
|
+
}
|
|
130
137
|
}
|
|
131
138
|
|
|
132
139
|
/**
|
|
@@ -259,6 +266,15 @@ class Findbar {
|
|
|
259
266
|
this.#boundsHandler = boundsHandler
|
|
260
267
|
}
|
|
261
268
|
|
|
269
|
+
/**
|
|
270
|
+
* Set whether to propagate visibility events to the parent window. If true, when the parent window is shown/hidden, the findbar will also be shown/hidden.
|
|
271
|
+
* @param {boolean} shouldPropagate - Whether to propagate visibility events. Default is true.
|
|
272
|
+
* @returns {void}
|
|
273
|
+
*/
|
|
274
|
+
propagateVisibilityEvents(shouldPropagate) {
|
|
275
|
+
this.#propagateVisibilityEvents = shouldPropagate
|
|
276
|
+
}
|
|
277
|
+
|
|
262
278
|
#registerKeyboardShortcuts(event, input) {
|
|
263
279
|
if (input.meta || input.control || input.alt) { return }
|
|
264
280
|
|
|
@@ -285,6 +301,12 @@ class Findbar {
|
|
|
285
301
|
}
|
|
286
302
|
}
|
|
287
303
|
}
|
|
304
|
+
|
|
305
|
+
#removeParent() {
|
|
306
|
+
this.close()
|
|
307
|
+
this.#parent = null
|
|
308
|
+
}
|
|
309
|
+
|
|
288
310
|
/**
|
|
289
311
|
* @param {Electron.FindInPageOptions} options
|
|
290
312
|
*/
|
|
@@ -313,16 +335,20 @@ class Findbar {
|
|
|
313
335
|
|
|
314
336
|
if (this.#parent && !this.#parent.isDestroyed()) {
|
|
315
337
|
boundsHandler()
|
|
316
|
-
this.#
|
|
317
|
-
|
|
338
|
+
if (this.#propagateVisibilityEvents) {
|
|
339
|
+
this.#parent.prependListener('show', showCascade)
|
|
340
|
+
this.#parent.prependListener('hide', hideCascade)
|
|
341
|
+
}
|
|
318
342
|
this.#parent.prependListener('resize', boundsHandler)
|
|
319
343
|
this.#parent.prependListener('move', boundsHandler)
|
|
320
344
|
}
|
|
321
345
|
|
|
322
346
|
this.#window.once('closed', () => {
|
|
323
347
|
if (this.#parent && !this.#parent.isDestroyed()) {
|
|
324
|
-
this.#
|
|
325
|
-
|
|
348
|
+
if (this.#propagateVisibilityEvents) {
|
|
349
|
+
this.#parent.off('show', showCascade)
|
|
350
|
+
this.#parent.off('hide', hideCascade)
|
|
351
|
+
}
|
|
326
352
|
this.#parent.off('resize', boundsHandler)
|
|
327
353
|
this.#parent.off('move', boundsHandler)
|
|
328
354
|
}
|
|
@@ -451,7 +477,7 @@ class Findbar {
|
|
|
451
477
|
}
|
|
452
478
|
|
|
453
479
|
/**
|
|
454
|
-
* Get the findbar instance for a given BrowserWindow or WebContents.
|
|
480
|
+
* Get the findbar instance for a given BrowserWindow or WebContents.
|
|
455
481
|
* @param {BrowserWindow | WebContents} windowOrWebContents
|
|
456
482
|
* @returns {Findbar | undefined} The findbar instance if it exists, otherwise undefined.
|
|
457
483
|
*/
|