electron-findbar 3.0.0 → 3.1.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/README.md +43 -0
- package/index.js +12 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -327,6 +327,49 @@ FindbarRemote.open()
|
|
|
327
327
|
FindbarRemote.inputChange('findIt')
|
|
328
328
|
```
|
|
329
329
|
|
|
330
|
+
## Changing the Parent Window
|
|
331
|
+
|
|
332
|
+
There are scenarios where you might need to change the parent window.
|
|
333
|
+
|
|
334
|
+
### Using updateParentWindow
|
|
335
|
+
|
|
336
|
+
The `updateParentWindow` method allows you to change the parent window while preserving the findbar instance and its state:
|
|
337
|
+
|
|
338
|
+
```javascript
|
|
339
|
+
// Create a findbar for the initial window
|
|
340
|
+
const findbar = Findbar.from(oldWindow, webContents)
|
|
341
|
+
|
|
342
|
+
// Later, when you need to change the parent:
|
|
343
|
+
findbar.updateParentWindow(newWindow)
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
This approach keeps the same findbar instance connected to the same webContents, but changes which window it's attached to. The findbar will close immediately.
|
|
347
|
+
|
|
348
|
+
### Using detach
|
|
349
|
+
|
|
350
|
+
Alternatively, the `detach` method disconnects a findbar instance from its webContents, allowing you to create a new instance in the next `Findbar.from` call:
|
|
351
|
+
|
|
352
|
+
```javascript
|
|
353
|
+
// Get the existing findbar
|
|
354
|
+
const oldFindbar = Findbar.fromIfExists(webContents)
|
|
355
|
+
|
|
356
|
+
// Detach it to free the association
|
|
357
|
+
if (oldFindbar) {
|
|
358
|
+
oldFindbar.detach()
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Now create a new findbar with a different parent
|
|
362
|
+
const newFindbar = Findbar.from([newWindow, ]webContents)
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
This approach is useful when you want to completely reset the findbar's configuration or when moving between very different window configurations.
|
|
366
|
+
|
|
367
|
+
### Important Considerations
|
|
368
|
+
|
|
369
|
+
- If the findbar is currently open when you change the parent window, it will automatically close.
|
|
370
|
+
- Window options and handlers will be preserved when using `updateParentWindow`.
|
|
371
|
+
- After calling `detach`, the old findbar instance can no longer be used.
|
|
372
|
+
|
|
330
373
|
## Author
|
|
331
374
|
|
|
332
375
|
Created by [Emerson Capuchi Romaneli](https://github.com/ECRomaneli) (@ECRomaneli).
|
package/index.js
CHANGED
|
@@ -74,6 +74,8 @@ class Findbar {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
this.#findableContents._findbar = this
|
|
77
|
+
|
|
78
|
+
this.#findableContents.once('destroyed', () => { this.detach() })
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
/**
|
|
@@ -116,10 +118,15 @@ class Findbar {
|
|
|
116
118
|
if (this.#window) { this.#window.webContents._findbar = void 0 }
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Update the parent window of the findbar.
|
|
123
|
+
* @param {BaseWindow} [newParent] - The new parent window. If not provided, the parent will be set to the window containing the web contents.
|
|
124
|
+
* @returns {void}
|
|
125
|
+
*/
|
|
126
|
+
updateParentWindow(newParent) {
|
|
127
|
+
if (this.#parent === newParent) { return }
|
|
128
|
+
this.close()
|
|
129
|
+
this.#parent = newParent ?? Findbar.#getBaseWindowFromWebContents(this.#findableContents)
|
|
123
130
|
}
|
|
124
131
|
|
|
125
132
|
/**
|
|
@@ -310,7 +317,7 @@ class Findbar {
|
|
|
310
317
|
this.#parent.prependListener('move', boundsHandler)
|
|
311
318
|
}
|
|
312
319
|
|
|
313
|
-
this.#window.once('
|
|
320
|
+
this.#window.once('closed', () => {
|
|
314
321
|
if (this.#parent && !this.#parent.isDestroyed()) {
|
|
315
322
|
this.#parent.off('show', showCascade)
|
|
316
323
|
this.#parent.off('hide', hideCascade)
|