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/issue 271 (#371)

Whitewaterb48d2c1393d3
diff --git a/libs/components/editor-blocks/src/blocks/numbered/NumberedView.tsx b/libs/components/editor-blocks/src/blocks/numbered/NumberedView.tsx
index c45321a138..ddf1375428 100644
--- a/libs/components/editor-blocks/src/blocks/numbered/NumberedView.tsx
+++ b/libs/components/editor-blocks/src/blocks/numbered/NumberedView.tsx
@@ -132,25 +132,31 @@ export const NumberedView = ({ block, editor }: CreateView) => {
// Move children to new block
const children = await block.children();
- await block.removeChildren();
- const next_node = await editor.createBlock(
+ const nextBlock = await editor.createBlock(
Protocol.Block.Type.numbered
);
- if (!next_node) {
+ if (!nextBlock) {
throw new Error('Failed to create todo block');
}
- await next_node.append(...children);
- await next_node.setProperties({
+ if (editor.getRootBlockId() === block.id) {
+ // If the block is the root block,
+ // new block can not append as next sibling,
+ // all new blocks should be append as children.
+ await block.insert(0, [nextBlock]);
+ editor.selectionManager.activeNodeByNodeId(nextBlock.id);
+ return true;
+ }
+ await block.removeChildren();
+ await nextBlock.append(...children);
+ await nextBlock.setProperties({
text: { value: after } as ContentColumnValue,
});
await block.setProperties({
text: { value: before } as ContentColumnValue,
});
- await block.after(next_node);
-
- editor.selectionManager.activeNodeByNodeId(next_node.id);
-
+ await block.after(nextBlock);
+ editor.selectionManager.activeNodeByNodeId(nextBlock.id);
return true;
};
const on_tab: TextProps['handleTab'] = async ({ isShiftKey }) => {
diff --git a/libs/components/editor-blocks/src/blocks/todo/TodoView.tsx b/libs/components/editor-blocks/src/blocks/todo/TodoView.tsx
index 6c9b6634cd..26d3e1ba4d 100644
--- a/libs/components/editor-blocks/src/blocks/todo/TodoView.tsx
+++ b/libs/components/editor-blocks/src/blocks/todo/TodoView.tsx
@@ -88,13 +88,21 @@ export const TodoView = ({ block, editor }: CreateView) => {
Boolean
) as AsyncBlock[];
- const next_node = await editor.createBlock(Protocol.Block.Type.todo);
- if (!next_node) {
+ const nextBlock = await editor.createBlock(Protocol.Block.Type.todo);
+ if (!nextBlock) {
throw new Error('Failed to create todo block');
}
+ if (editor.getRootBlockId() === block.id) {
+ // If the block is the root block,
+ // new block can not append as next sibling,
+ // all new blocks should be append as children.
+ await block.insert(0, [nextBlock]);
+ editor.selectionManager.activeNodeByNodeId(nextBlock.id);
+ return true;
+ }
await block.removeChildren();
- await next_node.append(...children);
- await next_node.setProperties({
+ await nextBlock.append(...children);
+ await nextBlock.setProperties({
text: { value: after } as ContentColumnValue,
});
@@ -102,9 +110,9 @@ export const TodoView = ({ block, editor }: CreateView) => {
text: { value: before } as ContentColumnValue,
collapsed: { value: false },
});
- await block.after(next_node);
+ await block.after(nextBlock);
- editor.selectionManager.activeNodeByNodeId(next_node.id);
+ editor.selectionManager.activeNodeByNodeId(nextBlock.id);
return true;
};
diff --git a/libs/components/editor-core/src/render-block/Context.tsx b/libs/components/editor-core/src/render-block/Context.tsx
index e5c0197eee..9783aa2754 100644
--- a/libs/components/editor-core/src/render-block/Context.tsx
+++ b/libs/components/editor-core/src/render-block/Context.tsx
@@ -1,9 +1,10 @@
import { genErrorObj } from '@toeverything/utils';
-import { createContext, PropsWithChildren, useContext } from 'react';
+import type { ComponentType, PropsWithChildren } from 'react';
+import { createContext, useContext } from 'react';
import { RenderBlockProps } from './RenderBlock';
type BlockRenderProps = {
- blockRender: (args: RenderBlockProps) => JSX.Element;
+ blockRender: ComponentType<RenderBlockProps>;
};
export const BlockRenderContext = createContext<BlockRenderProps>(