electron-findbar 0.2.1 → 0.3.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.
Files changed (3) hide show
  1. package/README.md +9 -1
  2. package/index.js +23 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -82,12 +82,20 @@ findbar.setWindowHandler(win => {
82
82
 
83
83
  ### Opening the Findbar
84
84
 
85
- The Findbar is a child window of the `BaseWindow` passed during construction. It will follow the relative movement of the parent window and must be visible for the Findbar to display:
85
+ The Findbar is a child window of the `BaseWindow` passed during construction. To open it use:
86
86
 
87
87
  ```js
88
88
  findbar.open();
89
89
  ```
90
90
 
91
+ On MacOS, the findbar will follow the relative movement of the parent window by default and there is no way to change it. On Windows and Linux, this behavior is not default and is simulated by using the `move` event of the parent and can be disabled by using:
92
+
93
+ ```js
94
+ findbar.followParentWindow(false)
95
+ ```
96
+
97
+ > Enabled by default.
98
+
91
99
  ### Finding Text in the Page
92
100
 
93
101
  Once open, the Findbar appears by default in the top-right corner of the parent window and can be used without additional coding. Alternatively, you can use the following methods to trigger `findInPage` and navigate through matches in the main process:
package/index.js CHANGED
@@ -23,6 +23,12 @@ class Findbar {
23
23
  /** @type {string} */
24
24
  #lastValue = ''
25
25
 
26
+ /**
27
+ * Workaround to fix "findInPage" bug - double-click to loop
28
+ * @type {boolean | null}
29
+ */
30
+ #fixMove = null
31
+
26
32
  /**
27
33
  * Prepare the findbar.
28
34
  * @param {BaseWindow} parent Parent window.
@@ -87,6 +93,10 @@ class Findbar {
87
93
  * Select previous match if any.
88
94
  */
89
95
  findPrevious() {
96
+ if (this.#matches.active === 1) {
97
+ this.#fixMove = false
98
+ }
99
+
90
100
  this.#searchableContents.findInPage(this.#lastValue, { forward: false })
91
101
  }
92
102
 
@@ -94,6 +104,10 @@ class Findbar {
94
104
  * Select next match if any.
95
105
  */
96
106
  findNext() {
107
+ if (this.#matches.active === this.#matches.total) {
108
+ this.#fixMove = true
109
+ }
110
+
97
111
  this.#searchableContents.findInPage(this.#lastValue, { forward: true })
98
112
  }
99
113
 
@@ -183,10 +197,7 @@ class Findbar {
183
197
  })
184
198
 
185
199
  this.#searchableContents.prependOnceListener('destroyed', () => { this.close() })
186
- this.#searchableContents.prependListener('found-in-page', (_e, result) => {
187
- this.#matches = result
188
- this.#sendMatchesCount(result.activeMatchOrdinal, result.matches)
189
- })
200
+ this.#searchableContents.prependListener('found-in-page', (_e, result) => { this.#sendMatchesCount(result.activeMatchOrdinal, result.matches) })
190
201
  }
191
202
 
192
203
  /**
@@ -207,7 +218,14 @@ class Findbar {
207
218
  * @param {number} total Total matches.
208
219
  */
209
220
  #sendMatchesCount(active, total) {
210
- this.#window.webContents.send('electron-findbar/matches', { active, total })
221
+ if (this.#fixMove !== null) {
222
+ this.#fixMove ? this.findNext() : this.findPrevious()
223
+ this.#fixMove = null
224
+ }
225
+
226
+ this.#matches = { active, total }
227
+
228
+ this.#window.webContents.send('electron-findbar/matches', this.#matches)
211
229
  }
212
230
 
213
231
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-findbar",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Chrome-like findbar for your Electron app.",
5
5
  "main": "index.js",
6
6
  "scripts": {