feat: surface more webContents
text selection commands (#37978)
* feat: surface more text selection commands * refactor: use options argument * docs: correct for review
This commit is contained in:
parent
a26343f3e0
commit
a8c0ed890f
5 changed files with 108 additions and 0 deletions
|
@ -1389,6 +1389,10 @@ Executes the editing command `cut` in web page.
|
|||
|
||||
Executes the editing command `copy` in web page.
|
||||
|
||||
#### `contents.centerSelection()`
|
||||
|
||||
Centers the current text selection in web page.
|
||||
|
||||
#### `contents.copyImageAt(x, y)`
|
||||
|
||||
* `x` Integer
|
||||
|
@ -1416,6 +1420,46 @@ Executes the editing command `selectAll` in web page.
|
|||
|
||||
Executes the editing command `unselect` in web page.
|
||||
|
||||
#### `contents.scrollToTop()`
|
||||
|
||||
Scrolls to the top of the current `webContents`.
|
||||
|
||||
#### `contents.scrollToBottom()`
|
||||
|
||||
Scrolls to the bottom of the current `webContents`.
|
||||
|
||||
#### `contents.adjustSelection(options)`
|
||||
|
||||
* `options` Object
|
||||
* `start` Number (optional) - Amount to shift the start index of the current selection.
|
||||
* `end` Number (optional) - Amount to shift the end index of the current selection.
|
||||
|
||||
Adjusts the current text selection starting and ending points in the focused frame by the given amounts. A negative amount moves the selection towards the beginning of the document, and a positive amount moves the selection towards the end of the document.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
const win = new BrowserWindow()
|
||||
|
||||
// Adjusts the beginning of the selection 1 letter forward,
|
||||
// and the end of the selection 5 letters forward.
|
||||
win.webContents.adjustSelection({ start: 1, end: 5 })
|
||||
|
||||
// Adjusts the beginning of the selection 2 letters forward,
|
||||
// and the end of the selection 3 letters backward.
|
||||
win.webContents.adjustSelection({ start: 2, end: -3 })
|
||||
```
|
||||
|
||||
For a call of `win.webContents.adjustSelection({ start: 1, end: 5 })`
|
||||
|
||||
Before:
|
||||
|
||||
<img width="487" alt="Image Before Text Selection Adjustment" src="https://user-images.githubusercontent.com/2036040/231761306-cd4e7b15-c2ed-46cf-8e80-10811f6de83e.png">
|
||||
|
||||
After:
|
||||
|
||||
<img width="487" alt="Image After Text Selection Adjustment" src="https://user-images.githubusercontent.com/2036040/231761169-887eb8ef-06fb-46e4-9efa-898bcb0d6a2b.png">
|
||||
|
||||
#### `contents.replace(text)`
|
||||
|
||||
* `text` string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue