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