mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
feat: allow search for doc without showing modal (#7138)
depends on https://github.com/toeverything/blocksuite/pull/7199#pullrequestreview-2095567573 fix TOV-858, fix AFF-1132
This commit is contained in:
@@ -208,9 +208,36 @@ export const BlocksuiteEdgelessEditor = forwardRef<
|
||||
BlocksuiteEditorProps
|
||||
>(function BlocksuiteEdgelessEditor({ page }, ref) {
|
||||
const [specs, portals] = usePatchSpecs(page, EdgelessModeSpecs);
|
||||
const editorRef = useRef<EdgelessEditor | null>(null);
|
||||
|
||||
const onDocRef = useCallback(
|
||||
(el: EdgelessEditor) => {
|
||||
editorRef.current = el;
|
||||
if (ref) {
|
||||
if (typeof ref === 'function') {
|
||||
ref(el);
|
||||
} else {
|
||||
ref.current = el;
|
||||
}
|
||||
}
|
||||
},
|
||||
[ref]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (editorRef.current) {
|
||||
editorRef.current.updateComplete
|
||||
.then(() => {
|
||||
// make sure editor can get keyboard events on showing up
|
||||
editorRef.current?.querySelector('affine-edgeless-root')?.click();
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<adapted.EdgelessEditor ref={ref} doc={page} specs={specs} />
|
||||
<adapted.EdgelessEditor ref={onDocRef} doc={page} specs={specs} />
|
||||
{portals}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -7,7 +7,10 @@ import {
|
||||
type useConfirmModal,
|
||||
type usePromptModal,
|
||||
} from '@affine/component';
|
||||
import type { QuickSearchService } from '@affine/core/modules/cmdk';
|
||||
import type {
|
||||
QuickSearchService,
|
||||
SearchCallbackResult,
|
||||
} from '@affine/core/modules/cmdk';
|
||||
import type { PeekViewService } from '@affine/core/modules/peek-view';
|
||||
import type { ActivePeekView } from '@affine/core/modules/peek-view/entities/peek-view';
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
@@ -254,13 +257,34 @@ export function patchQuickSearchService(
|
||||
patchSpecService(rootSpec, pageService => {
|
||||
pageService.quickSearchService = {
|
||||
async searchDoc(options) {
|
||||
const result = await service.quickSearch.search(options.userInput);
|
||||
if (result) {
|
||||
if ('docId' in result) {
|
||||
return result;
|
||||
let searchResult: SearchCallbackResult | null = null;
|
||||
if (options.skipSelection) {
|
||||
const query = options.userInput;
|
||||
if (!query) {
|
||||
logger.error('No user input provided');
|
||||
} else {
|
||||
const searchedDoc = service.quickSearch
|
||||
.getSearchedDocs(query)
|
||||
.at(0);
|
||||
if (searchedDoc) {
|
||||
searchResult = {
|
||||
docId: searchedDoc.doc.id,
|
||||
blockId: searchedDoc.blockId,
|
||||
action: 'insert',
|
||||
query,
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
searchResult = await service.quickSearch.search(options.userInput);
|
||||
}
|
||||
|
||||
if (searchResult) {
|
||||
if ('docId' in searchResult) {
|
||||
return searchResult;
|
||||
} else {
|
||||
return {
|
||||
userInput: result.query,
|
||||
userInput: searchResult.query,
|
||||
action: 'insert',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user