There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
fix(editor): do not display format bar with embed node (#11371)
Flrande51b3f2b0572b
diff --git a/blocksuite/affine/inlines/preset/src/command/utils.ts b/blocksuite/affine/inlines/preset/src/command/utils.tsindex c0443b0011..3552909d49 100644--- a/blocksuite/affine/inlines/preset/src/command/utils.ts+++ b/blocksuite/affine/inlines/preset/src/command/utils.ts@@ -202,8 +202,25 @@ export function getCombinedTextStyle(chain: Chain<InitCommandCtx>) {}export function isFormatSupported(chain: Chain<InitCommandCtx>) {- return handleCurrentSelection(- chain,- (_type, inlineEditors) => inlineEditors.length > 0- );+ return handleCurrentSelection(chain, (_type, inlineEditors) => {+ if (inlineEditors.length === 1) {+ const inlineEditor = inlineEditors[0];+ const inlineRange = inlineEditor.getInlineRange();++ // support block selection+ if (!inlineRange) return true;++ if (inlineRange.length !== 1) return true;++ // skip embed node+ const delta = inlineEditor.getDeltaByRangeIndex(inlineRange.index + 1);+ if (!delta) return true;++ const isEmbed = inlineEditor.isEmbed(delta);+ if (isEmbed) return false;++ return true;+ }+ return inlineEditors.length > 0;+ });}diff --git a/tests/blocksuite/e2e/format-bar.spec.ts b/tests/blocksuite/e2e/format-bar.spec.tsindex c600b1c3cd..b84b6a3d55 100644--- a/tests/blocksuite/e2e/format-bar.spec.ts+++ b/tests/blocksuite/e2e/format-bar.spec.ts@@ -19,6 +19,7 @@ import {initThreeParagraphs,pasteByKeyboard,pressArrowDown,+ pressArrowLeft,pressArrowUp,pressEnter,pressEscape,@@ -1051,3 +1052,18 @@ test.describe('more menu button', () => {await assertRichTexts(page, ['123', '789']);});});++test('should not display format bar when just select embed node', async ({+ page,+}) => {+ await enterPlaygroundRoom(page);+ await initEmptyParagraphState(page);+ await focusRichText(page, 0);+ await type(page, '@\n');+ await assertRichTextInlineRange(page, 0, 1, 0);+ await pressArrowLeft(page);+ await assertRichTextInlineRange(page, 0, 0, 1);++ const { boldBtn } = getFormatBar(page);+ await expect(boldBtn).toBeHidden();+});