Skip to content

Commit b4e639c

Browse files
committed
♻️(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.
1 parent ba962af commit b4e639c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,14 @@ const AIMenuItem = ({
281281
const handleAIError = useHandleAIError();
282282

283283
const handleAIAction = async () => {
284-
const selectedBlocks = editor.getSelection()?.blocks;
284+
let selectedBlocks = editor.getSelection()?.blocks;
285285

286286
if (!selectedBlocks || selectedBlocks.length === 0) {
287-
return;
287+
selectedBlocks = [editor.getTextCursorPosition().block];
288+
289+
if (!selectedBlocks || selectedBlocks.length === 0) {
290+
return;
291+
}
288292
}
289293

290294
const markdown = await editor.blocksToMarkdownLossy(selectedBlocks);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export function MarkdownButton() {
4646
const { t } = useTranslation();
4747

4848
const handleConvertMarkdown = () => {
49-
const blocks = editor.getSelection()?.blocks;
49+
let blocks = editor.getSelection()?.blocks;
50+
51+
if (!blocks || blocks.length === 0) {
52+
blocks = [editor.getTextCursorPosition().block];
53+
}
5054

5155
forEach(blocks, async (block) => {
5256
if (!isBlock(block as unknown as Block)) {

0 commit comments

Comments
 (0)