electron-findbar 0.3.0 → 0.4.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/index.js +30 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const { BaseWindow, BrowserWindow, WebContents, BrowserWindowConstructorOptions, Rectangle } = require('electron')
|
|
2
|
-
const path = require('node:path')
|
|
3
2
|
|
|
4
3
|
class Findbar {
|
|
5
4
|
/** @type {BaseWindow} */
|
|
@@ -23,6 +22,9 @@ class Findbar {
|
|
|
23
22
|
/** @type {string} */
|
|
24
23
|
#lastValue = ''
|
|
25
24
|
|
|
25
|
+
/** @type {boolean} */
|
|
26
|
+
#followParent = process.platform !== 'darwin'
|
|
27
|
+
|
|
26
28
|
/**
|
|
27
29
|
* Workaround to fix "findInPage" bug - double-click to loop
|
|
28
30
|
* @type {boolean | null}
|
|
@@ -60,7 +62,7 @@ class Findbar {
|
|
|
60
62
|
|
|
61
63
|
this.#windowHandler && this.#windowHandler(this.#window)
|
|
62
64
|
|
|
63
|
-
this.#window.loadFile(
|
|
65
|
+
this.#window.loadFile(`${__dirname}/web/findbar.html`)
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
/**
|
|
@@ -154,6 +156,18 @@ class Findbar {
|
|
|
154
156
|
this.#windowHandler = windowHandler
|
|
155
157
|
}
|
|
156
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Set the findbar to follow the parent window. Default is true.
|
|
161
|
+
*
|
|
162
|
+
* On darwin platform, the findbar follows the parent window by default. This method is set
|
|
163
|
+
* to false to not create a "move" event listener unnescessarily.
|
|
164
|
+
* @platform win32,linux
|
|
165
|
+
* @param {boolean} follow If true, the findbar will follow the parent window movement.
|
|
166
|
+
*/
|
|
167
|
+
followParentWindow(follow) {
|
|
168
|
+
this.#followParent = follow
|
|
169
|
+
}
|
|
170
|
+
|
|
157
171
|
/**
|
|
158
172
|
* Merge custom, defaults, and fixed options.
|
|
159
173
|
* @param {Electron.BrowserWindowConstructorOptions} options Custom options.
|
|
@@ -183,15 +197,28 @@ class Findbar {
|
|
|
183
197
|
* Register all event listeners.
|
|
184
198
|
*/
|
|
185
199
|
#registerListeners() {
|
|
200
|
+
const followParent = this.#followParent
|
|
186
201
|
const showCascade = () => this.#window.isVisible() || this.#window.show()
|
|
187
202
|
const hideCascade = () => this.#window.isVisible() && this.#window.hide()
|
|
203
|
+
|
|
204
|
+
let lastPos = this.#parent.getPosition()
|
|
205
|
+
const moveCascade = () => {
|
|
206
|
+
const newPos = this.#parent.getPosition()
|
|
207
|
+
const diff = { x: newPos[0] - lastPos[0], y: newPos[1] - lastPos[1] }
|
|
208
|
+
lastPos = newPos
|
|
209
|
+
|
|
210
|
+
const { x, y } = this.#window.getBounds()
|
|
211
|
+
this.#window.setPosition(x + diff.x, y + diff.y)
|
|
212
|
+
}
|
|
188
213
|
|
|
189
214
|
this.#parent.prependListener('show', showCascade)
|
|
190
215
|
this.#parent.prependListener('hide', hideCascade)
|
|
216
|
+
followParent && this.#parent.prependListener('move', moveCascade)
|
|
191
217
|
|
|
192
|
-
this.#window.once('
|
|
218
|
+
this.#window.once('close', () => {
|
|
193
219
|
this.#parent.off('show', showCascade)
|
|
194
220
|
this.#parent.off('hide', hideCascade)
|
|
221
|
+
followParent && this.#parent.off('move', moveCascade)
|
|
195
222
|
this.#window = null
|
|
196
223
|
this.stopFind()
|
|
197
224
|
})
|