Skip to content

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.

fix: commend-menu create block can leave menu name

DiamondThree88639ea8bbc8
diff --git a/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx b/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx
index 66b2679220..80afb0726b 100644
--- a/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx
+++ b/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx
@@ -211,6 +211,8 @@ export const CommandMenu = ({ editor, hooks, style }: CommandMenuProps) => {
const handleSelected = async (type: BlockFlavorKeys | string) => {
const text = await editor.commands.textCommands.getBlockText(blockId);
+ const block = await editor.getBlockById(blockId);
+ let textValue = block.getProperty('text').value;
editor.blockHelper.removeSearchSlash(blockId, true);
if (type.startsWith('Virgo')) {
const handler =
@@ -223,14 +225,18 @@ export const CommandMenu = ({ editor, hooks, style }: CommandMenuProps) => {
} else {
await commonCommandMenuHandler(blockId, type, editor);
}
- const block = await editor.getBlockById(blockId);
const nextBlock = await block.nextSibling();
setTimeout(() => {
editor.selectionManager.activeNodeByNodeId(nextBlock.id);
+ if (textValue.length === 1) {
+ block.remove();
+ } else {
+ block.setProperty('text', {
+ //@ts-ignore
+ value: textValue.filter(text => !text.search),
+ });
+ }
}, 100);
- if (block.blockProvider.isEmpty()) {
- block.remove();
- }
} else {
if (Protocol.Block.Type[type as BlockFlavorKeys]) {
const block = await editor.commands.blockCommands.convertBlock(