♻️(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:
@@ -281,10 +281,14 @@ const AIMenuItem = ({
|
|||||||
const handleAIError = useHandleAIError();
|
const handleAIError = useHandleAIError();
|
||||||
|
|
||||||
const handleAIAction = async () => {
|
const handleAIAction = async () => {
|
||||||
const selectedBlocks = editor.getSelection()?.blocks;
|
let selectedBlocks = editor.getSelection()?.blocks;
|
||||||
|
|
||||||
if (!selectedBlocks || selectedBlocks.length === 0) {
|
if (!selectedBlocks || selectedBlocks.length === 0) {
|
||||||
return;
|
selectedBlocks = [editor.getTextCursorPosition().block];
|
||||||
|
|
||||||
|
if (!selectedBlocks || selectedBlocks.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const markdown = await editor.blocksToMarkdownLossy(selectedBlocks);
|
const markdown = await editor.blocksToMarkdownLossy(selectedBlocks);
|
||||||
|
|||||||
@@ -46,7 +46,11 @@ export function MarkdownButton() {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const handleConvertMarkdown = () => {
|
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) => {
|
forEach(blocks, async (block) => {
|
||||||
if (!isBlock(block as unknown as Block)) {
|
if (!isBlock(block as unknown as Block)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user