Skip to content

Commit 4d24e5c

Browse files
committed
Merge pull request DefinitelyTyped#8583 from rhysd/missing-webContents-APIs
github-electron: Added findInPage(), stopFindInPage() and insertText() for WebContents
2 parents 42fce07 + 31d9888 commit 4d24e5c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

github-electron/github-electron-main-tests.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ app.on('ready', () => {
109109
mainWindow.webContents.executeJavaScript('return true;');
110110
mainWindow.webContents.executeJavaScript('return true;', true);
111111
mainWindow.webContents.executeJavaScript('return true;', true, (result: boolean) => console.log(result));
112+
mainWindow.webContents.insertText('blah, blah, blah');
113+
mainWindow.webContents.findInPage('blah');
114+
mainWindow.webContents.findInPage('blah', {
115+
forward: true,
116+
matchCase: false,
117+
});
118+
mainWindow.webContents.stopFindInPage('clearSelection');
119+
mainWindow.webContents.stopFindInPage('keepSelection');
120+
mainWindow.webContents.stopFindInPage('activateSelection');
112121
});
113122

114123
// Locale

github-electron/github-electron.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,14 @@ declare namespace Electron {
537537
height?: number;
538538
}
539539

540+
interface FindInPageOptions {
541+
forward?: boolean;
542+
findNext?: boolean;
543+
matchCase?: boolean;
544+
wordStart?: boolean;
545+
medialCapitalAsWordStart?: boolean;
546+
}
547+
540548
/**
541549
* A WebContents is responsible for rendering and controlling a web page.
542550
*/
@@ -677,6 +685,26 @@ declare namespace Electron {
677685
* Executes Edit -> Replace Misspelling command in page.
678686
*/
679687
replaceMisspelling(text: string): void;
688+
/**
689+
* Inserts text to the focused element.
690+
*/
691+
insertText(text: string): void;
692+
/**
693+
* Starts a request to find all matches for the text in the web page and
694+
* returns an Integer representing the request id used for the request.
695+
* The result of the request can be obtained by subscribing to
696+
* found-in-page event.
697+
*/
698+
findInPage(text: string, options?: FindInPageOptions): void;
699+
/**
700+
* Stops any findInPage request for the webContents with the provided
701+
* action.
702+
* @param action Specifies the action to take place when ending webContents.findInPage request.
703+
* 'clearSelection' - Translate the selection into a normal selection.
704+
* 'keepSelection' - Clear the selection.
705+
* 'activateSelection' - Focus and click the selection node.
706+
*/
707+
stopFindInPage(action: 'clearSelection' | 'keepSelection' | 'activateSelection'): void;
680708
/**
681709
* Checks if any serviceworker is registered.
682710
*/

0 commit comments

Comments
 (0)