Skip to content

Commit 2eac291

Browse files
committed
fixup! ✨(frontend) Add "Copy link to block" feature
1 parent 804db8b commit 2eac291

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

  • src/frontend/apps/impress/src/features/docs/doc-editor/components/DocsSideMenu

src/frontend/apps/impress/src/features/docs/doc-editor/components/DocsSideMenu/LinkToBlockItem.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import { useTranslation } from 'react-i18next';
1010
import { Box } from '@/components';
1111
import { useClipboard } from '@/hooks';
1212
import LinkIcon from '@/icons/link.svg';
13+
import { useResponsiveStore } from '@/stores/useResponsiveStore';
1314

1415
import type { DocsBlockNoteEditor } from '../../types';
1516

1617
export const LinkToBlockItem = () => {
1718
const { t } = useTranslation();
19+
const { isMobile } = useResponsiveStore();
1820
const Components = useComponentsContext();
1921
const editor: DocsBlockNoteEditor = useBlockNoteEditor();
2022
const copyToClipboard = useClipboard();
@@ -24,7 +26,7 @@ export const LinkToBlockItem = () => {
2426
});
2527

2628
const copyLinkToBlock = useCallback(() => {
27-
if (!block) {
29+
if (!block?.id) {
2830
return;
2931
}
3032

@@ -33,7 +35,13 @@ export const LinkToBlockItem = () => {
3335
t('Link Copied !'),
3436
t('Failed to copy link'),
3537
);
36-
}, [block, copyToClipboard, t]);
38+
39+
if (!isMobile) {
40+
editor.focus();
41+
}
42+
43+
editor.setTextCursorPosition(block.id, 'end');
44+
}, [block?.id, copyToClipboard, editor, isMobile, t]);
3745

3846
if (Components === undefined || block === undefined) {
3947
return null;

0 commit comments

Comments
 (0)