Skip to content

Commit 00b223f

Browse files
committed
🔥(frontend) hide markdown button if not text
If we are selected a block that is not a text block, we hide the markdown button.
1 parent 38b32c1 commit 00b223f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import {
1111
UnnestBlockButton,
1212
useBlockNoteEditor,
1313
useComponentsContext,
14+
useSelectedBlocks,
1415
} from '@blocknote/react';
1516
import { forEach, isArray } from 'lodash';
16-
import React from 'react';
17+
import React, { useMemo } from 'react';
1718

1819
export const BlockNoteToolbar = () => {
1920
return (
@@ -91,6 +92,7 @@ const recursiveContent = (content: Block[], base: string = '') => {
9192
export function MarkdownButton() {
9293
const editor = useBlockNoteEditor();
9394
const Components = useComponentsContext();
95+
const selectedBlocks = useSelectedBlocks(editor);
9496

9597
const handleConvertMarkdown = () => {
9698
const blocks = editor.getSelection()?.blocks;
@@ -114,7 +116,11 @@ export function MarkdownButton() {
114116
});
115117
};
116118

117-
if (!Components) {
119+
const show = useMemo(() => {
120+
return !!selectedBlocks.find((block) => block.content !== undefined);
121+
}, [selectedBlocks]);
122+
123+
if (!show || !editor.isEditable || !Components) {
118124
return null;
119125
}
120126

0 commit comments

Comments
 (0)