feat(core): cmd+f search in doc function (#7040)

You can use the cmd+F shortcut key to trigger the FindInPage function.
This commit is contained in:
JimmFly
2024-05-28 06:19:48 +00:00
parent 5759c15de3
commit bd9c929d05
19 changed files with 440 additions and 4 deletions

View File

@@ -0,0 +1,17 @@
export const findInPageHandlers = {
findInPage: async (
event: Electron.IpcMainInvokeEvent,
text: string,
options?: Electron.FindInPageOptions
) => {
const webContents = event.sender;
return webContents.findInPage(text, options);
},
stopFindInPage: async (
event: Electron.IpcMainInvokeEvent,
action: 'clearSelection' | 'keepSelection' | 'activateSelection'
) => {
const webContents = event.sender;
return webContents.stopFindInPage(action);
},
};

View File

@@ -0,0 +1 @@
export * from './handlers';

View File

@@ -3,6 +3,7 @@ import { ipcMain } from 'electron';
import { clipboardHandlers } from './clipboard';
import { configStorageHandlers } from './config-storage';
import { exportHandlers } from './export';
import { findInPageHandlers } from './find-in-page';
import { getLogFilePath, logger, revealLogFile } from './logger';
import { uiHandlers } from './ui/handlers';
import { updaterHandlers } from './updater';
@@ -24,6 +25,7 @@ export const allHandlers = {
export: exportHandlers,
updater: updaterHandlers,
configStorage: configStorageHandlers,
findInPage: findInPageHandlers,
};
export const registerHandlers = () => {

View File

@@ -169,6 +169,16 @@ async function createWindow(additionalArguments: string[]) {
uiSubjects.onFullScreen$.next(false);
});
browserWindow.webContents.on('found-in-page', (_event, result) => {
const { requestId, activeMatchOrdinal, matches, finalUpdate } = result;
browserWindow.webContents.send('found-in-page-result', {
requestId,
activeMatchOrdinal,
matches,
finalUpdate,
});
});
/**
* URL for main window.
*/