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

@@ -1,6 +1,6 @@
import { contextBridge } from 'electron';
import { affine, appInfo, getElectronAPIs } from './electron-api';
import { affine, appInfo, cmdFind, getElectronAPIs } from './electron-api';
const { apis, events } = getElectronAPIs();
@@ -10,6 +10,7 @@ contextBridge.exposeInMainWorld('events', events);
try {
contextBridge.exposeInMainWorld('affine', affine);
contextBridge.exposeInMainWorld('cmdFind', cmdFind);
} catch (error) {
console.error('Failed to expose affine APIs to window object!', error);
}

View File

@@ -47,6 +47,20 @@ export const affine = {
},
};
export const cmdFind = {
findInPage: (text: string, options?: Electron.FindInPageOptions) =>
ipcRenderer.invoke('findInPage:findInPage', text, options),
stopFindInPage: (
action: 'clearSelection' | 'keepSelection' | 'activateSelection'
) => ipcRenderer.invoke('findInPage:stopFindInPage', action),
onFindInPageResult: (callBack: (data: any) => void) =>
ipcRenderer.on('found-in-page-result', (_event, data) => callBack(data)),
offFindInPageResult: (callBack: (data: any) => void) =>
ipcRenderer.removeListener('found-in-page-result', (_event, data) =>
callBack(data)
),
};
export function getElectronAPIs() {
const mainAPIs = getMainAPIs();
const helperAPIs = getHelperAPIs();