From b4e639cc24cf54b63ae4d8c9f89e1209d4ecce74 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Thu, 5 Dec 2024 23:20:02 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(frontend)=20adapt=20Blocknot?= =?UTF-8?q?e=20button?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Last upgrade of Blocknote changes the editor method getSelection, the blocks were not being selected in certain cases. We updated the methods to select the blocks correctly. --- .../src/features/docs/doc-editor/components/AIButton.tsx | 8 ++++++-- .../docs/doc-editor/components/MarkdownButton.tsx | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/components/AIButton.tsx b/src/frontend/apps/impress/src/features/docs/doc-editor/components/AIButton.tsx index c7915bfe..31c98291 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-editor/components/AIButton.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/components/AIButton.tsx @@ -281,10 +281,14 @@ const AIMenuItem = ({ const handleAIError = useHandleAIError(); const handleAIAction = async () => { - const selectedBlocks = editor.getSelection()?.blocks; + let selectedBlocks = editor.getSelection()?.blocks; if (!selectedBlocks || selectedBlocks.length === 0) { - return; + selectedBlocks = [editor.getTextCursorPosition().block]; + + if (!selectedBlocks || selectedBlocks.length === 0) { + return; + } } const markdown = await editor.blocksToMarkdownLossy(selectedBlocks); diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/components/MarkdownButton.tsx b/src/frontend/apps/impress/src/features/docs/doc-editor/components/MarkdownButton.tsx index f84f1cd2..7cae642a 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-editor/components/MarkdownButton.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/components/MarkdownButton.tsx @@ -46,7 +46,11 @@ export function MarkdownButton() { const { t } = useTranslation(); const handleConvertMarkdown = () => { - const blocks = editor.getSelection()?.blocks; + let blocks = editor.getSelection()?.blocks; + + if (!blocks || blocks.length === 0) { + blocks = [editor.getTextCursorPosition().block]; + } forEach(blocks, async (block) => { if (!isBlock(block as unknown as Block)) {