mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-02 01:22:05 +03:00
fix(core): disable quick search when the link-popup is visitable (#5409)
close AFF-471
This commit is contained in:
parent
f5b74ca8a9
commit
971f2beed1
@ -1,5 +1,6 @@
|
|||||||
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import { SettingsIcon } from '@blocksuite/icons';
|
import { SettingsIcon } from '@blocksuite/icons';
|
||||||
|
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||||
import { appSettingAtom } from '@toeverything/infra/atom';
|
import { appSettingAtom } from '@toeverything/infra/atom';
|
||||||
import {
|
import {
|
||||||
PreconditionStrategy,
|
PreconditionStrategy,
|
||||||
@ -16,11 +17,13 @@ export function registerAffineSettingsCommands({
|
|||||||
store,
|
store,
|
||||||
theme,
|
theme,
|
||||||
languageHelper,
|
languageHelper,
|
||||||
|
editor,
|
||||||
}: {
|
}: {
|
||||||
t: ReturnType<typeof useAFFiNEI18N>;
|
t: ReturnType<typeof useAFFiNEI18N>;
|
||||||
store: ReturnType<typeof createStore>;
|
store: ReturnType<typeof createStore>;
|
||||||
theme: ReturnType<typeof useTheme>;
|
theme: ReturnType<typeof useTheme>;
|
||||||
languageHelper: ReturnType<typeof useLanguageHelper>;
|
languageHelper: ReturnType<typeof useLanguageHelper>;
|
||||||
|
editor: AffineEditorContainer | null;
|
||||||
}) {
|
}) {
|
||||||
const unsubs: Array<() => void> = [];
|
const unsubs: Array<() => void> = [];
|
||||||
const { onLanguageChange, languagesList, currentLanguage } = languageHelper;
|
const { onLanguageChange, languagesList, currentLanguage } = languageHelper;
|
||||||
@ -36,7 +39,18 @@ export function registerAffineSettingsCommands({
|
|||||||
icon: <SettingsIcon />,
|
icon: <SettingsIcon />,
|
||||||
run() {
|
run() {
|
||||||
const quickSearchModalState = store.get(openQuickSearchModalAtom);
|
const quickSearchModalState = store.get(openQuickSearchModalAtom);
|
||||||
store.set(openQuickSearchModalAtom, !quickSearchModalState);
|
|
||||||
|
if (!editor) {
|
||||||
|
return store.set(openQuickSearchModalAtom, !quickSearchModalState);
|
||||||
|
}
|
||||||
|
// Due to a conflict with the shortcut for creating a link after selecting text in blocksuite,
|
||||||
|
// opening the quick search modal is disabled when link-popup is visitable.
|
||||||
|
const textSelection = editor.host?.std.selection.find('text');
|
||||||
|
if (textSelection && textSelection.from.length > 0) {
|
||||||
|
const linkPopup = document.querySelector('link-popup');
|
||||||
|
if (linkPopup) return;
|
||||||
|
}
|
||||||
|
return store.set(openQuickSearchModalAtom, !quickSearchModalState);
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -96,7 +96,7 @@ const PageDetailEditorMain = memo(function PageDetailEditorMain({
|
|||||||
[isPublic, switchToEdgelessMode, pageId, switchToPageMode]
|
[isPublic, switchToEdgelessMode, pageId, switchToPageMode]
|
||||||
);
|
);
|
||||||
|
|
||||||
const [, setEditor] = useState<AffineEditorContainer>();
|
const [editor, setEditor] = useState<AffineEditorContainer>();
|
||||||
const blockId = useRouterHash();
|
const blockId = useRouterHash();
|
||||||
|
|
||||||
const onLoadEditor = useCallback(
|
const onLoadEditor = useCallback(
|
||||||
@ -125,11 +125,13 @@ const PageDetailEditorMain = memo(function PageDetailEditorMain({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const [, setActiveBlocksuiteEditor] = useActiveBlocksuiteEditor();
|
const [, setActiveBlocksuiteEditor] = useActiveBlocksuiteEditor();
|
||||||
const editor = useRef<AffineEditorContainer>(null);
|
const editorRef = useRef<AffineEditorContainer | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setActiveBlocksuiteEditor(editor.current);
|
if (editor) {
|
||||||
}, [setActiveBlocksuiteEditor]);
|
setActiveBlocksuiteEditor(editorRef.current);
|
||||||
|
}
|
||||||
|
}, [editor, setActiveBlocksuiteEditor]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Editor
|
<Editor
|
||||||
@ -147,7 +149,7 @@ const PageDetailEditorMain = memo(function PageDetailEditorMain({
|
|||||||
onModeChange={setEditorMode}
|
onModeChange={setEditorMode}
|
||||||
defaultSelectedBlockId={blockId}
|
defaultSelectedBlockId={blockId}
|
||||||
onLoadEditor={onLoadEditor}
|
onLoadEditor={onLoadEditor}
|
||||||
ref={editor}
|
ref={editorRef}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -15,6 +15,7 @@ import {
|
|||||||
} from '../commands';
|
} from '../commands';
|
||||||
import { usePageHelper } from '../components/blocksuite/block-suite-page-list/utils';
|
import { usePageHelper } from '../components/blocksuite/block-suite-page-list/utils';
|
||||||
import { useLanguageHelper } from './affine/use-language-helper';
|
import { useLanguageHelper } from './affine/use-language-helper';
|
||||||
|
import { useActiveBlocksuiteEditor } from './use-block-suite-editor';
|
||||||
import { useNavigateHelper } from './use-navigate-helper';
|
import { useNavigateHelper } from './use-navigate-helper';
|
||||||
|
|
||||||
export function useRegisterWorkspaceCommands() {
|
export function useRegisterWorkspaceCommands() {
|
||||||
@ -26,6 +27,7 @@ export function useRegisterWorkspaceCommands() {
|
|||||||
const pageHelper = usePageHelper(currentWorkspace.blockSuiteWorkspace);
|
const pageHelper = usePageHelper(currentWorkspace.blockSuiteWorkspace);
|
||||||
const navigationHelper = useNavigateHelper();
|
const navigationHelper = useNavigateHelper();
|
||||||
const [pageListMode, setPageListMode] = useAtom(allPageModeSelectAtom);
|
const [pageListMode, setPageListMode] = useAtom(allPageModeSelectAtom);
|
||||||
|
const [editor] = useActiveBlocksuiteEditor();
|
||||||
|
|
||||||
// register AffineUpdatesCommands
|
// register AffineUpdatesCommands
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -69,12 +71,13 @@ export function useRegisterWorkspaceCommands() {
|
|||||||
t,
|
t,
|
||||||
theme,
|
theme,
|
||||||
languageHelper,
|
languageHelper,
|
||||||
|
editor,
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
unsub();
|
unsub();
|
||||||
};
|
};
|
||||||
}, [store, t, theme, languageHelper]);
|
}, [store, t, theme, languageHelper, editor]);
|
||||||
|
|
||||||
// register AffineLayoutCommands
|
// register AffineLayoutCommands
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -442,3 +442,30 @@ test('Create a new page with special characters in the title and search for this
|
|||||||
await page.waitForTimeout(300);
|
await page.waitForTimeout(300);
|
||||||
await assertTitle(page, specialTitle);
|
await assertTitle(page, specialTitle);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('disable quick search when the link-popup is visitable', async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
const specialTitle = '"test"';
|
||||||
|
|
||||||
|
await openHomePage(page);
|
||||||
|
await waitForEditorLoad(page);
|
||||||
|
await clickNewPageButton(page);
|
||||||
|
|
||||||
|
await openQuickSearchByShortcut(page);
|
||||||
|
const quickSearch = page.locator('[data-testid=cmdk-quick-search]');
|
||||||
|
await expect(quickSearch).toBeVisible();
|
||||||
|
await withCtrlOrMeta(page, () => page.keyboard.press('k', { delay: 50 }));
|
||||||
|
|
||||||
|
await getBlockSuiteEditorTitle(page).click();
|
||||||
|
await getBlockSuiteEditorTitle(page).fill(specialTitle);
|
||||||
|
await page.keyboard.press('Enter', { delay: 10 });
|
||||||
|
await page.keyboard.insertText('123456');
|
||||||
|
await page.getByText('123456').dblclick();
|
||||||
|
|
||||||
|
await withCtrlOrMeta(page, () => page.keyboard.press('k', { delay: 50 }));
|
||||||
|
const linkPopup = page.locator('.affine-link-popover');
|
||||||
|
await expect(linkPopup).toBeVisible();
|
||||||
|
const currentQuickSearch = page.locator('[data-testid=cmdk-quick-search]');
|
||||||
|
await expect(currentQuickSearch).not.toBeVisible();
|
||||||
|
});
|
||||||
|
@ -54,6 +54,7 @@ function useRegisterCommands() {
|
|||||||
],
|
],
|
||||||
currentLanguage: undefined,
|
currentLanguage: undefined,
|
||||||
},
|
},
|
||||||
|
editor: null,
|
||||||
}),
|
}),
|
||||||
registerAffineCreationCommands({
|
registerAffineCreationCommands({
|
||||||
t,
|
t,
|
||||||
|
Loading…
Reference in New Issue
Block a user