mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 13:58:50 +08:00
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:
@@ -0,0 +1,34 @@
|
||||
import { FindInPageService } from '@affine/core/modules/find-in-page/services/find-in-page';
|
||||
import { registerAffineCommand, useService } from '@toeverything/infra';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
|
||||
export function useRegisterFindInPageCommands() {
|
||||
const findInPage = useService(FindInPageService).findInPage;
|
||||
const toggleVisible = useCallback(() => {
|
||||
findInPage.toggleVisible();
|
||||
}, [findInPage]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!environment.isDesktop) {
|
||||
return;
|
||||
}
|
||||
const unsubs: Array<() => void> = [];
|
||||
unsubs.push(
|
||||
registerAffineCommand({
|
||||
id: `editor:find-in-page`,
|
||||
keyBinding: {
|
||||
binding: '$mod+f',
|
||||
},
|
||||
icon: null,
|
||||
label: '',
|
||||
run() {
|
||||
toggleVisible();
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubs.forEach(unsub => unsub());
|
||||
};
|
||||
}, [toggleVisible]);
|
||||
}
|
||||
Reference in New Issue
Block a user