♻️(frontend) adapt Blocknote button

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.
This commit is contained in:
Anthony LC
2024-12-05 23:20:02 +01:00
committed by Anthony LC
parent ba962af914
commit b4e639cc24
2 changed files with 11 additions and 3 deletions

View File

@@ -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);

View File

@@ -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)) {