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: handle root block when indent
lawvs42f02aed5c0e
diff --git a/libs/components/editor-blocks/src/blocks/bullet/BulletView.tsx b/libs/components/editor-blocks/src/blocks/bullet/BulletView.tsxindex 5a15a78554..9f77eda6cb 100644--- a/libs/components/editor-blocks/src/blocks/bullet/BulletView.tsx+++ b/libs/components/editor-blocks/src/blocks/bullet/BulletView.tsx@@ -173,7 +173,7 @@ export const BulletView = ({ block, editor }: CreateView) => {}return true;} else {- return tabBlock(block, isShiftKey);+ return tabBlock(editor, block, isShiftKey);}};diff --git a/libs/components/editor-blocks/src/blocks/numbered/NumberedView.tsx b/libs/components/editor-blocks/src/blocks/numbered/NumberedView.tsxindex ec0d690c96..38dac6fc75 100644--- a/libs/components/editor-blocks/src/blocks/numbered/NumberedView.tsx+++ b/libs/components/editor-blocks/src/blocks/numbered/NumberedView.tsx@@ -167,7 +167,7 @@ export const NumberedView = ({ block, editor }: CreateView) => {}return true;} else {- tabBlock(block, isShiftKey);+ tabBlock(editor, block, isShiftKey);return false;}};diff --git a/libs/components/editor-blocks/src/blocks/text/TextView.tsx b/libs/components/editor-blocks/src/blocks/text/TextView.tsxindex 2a9d77d577..e319f9e863 100644--- a/libs/components/editor-blocks/src/blocks/text/TextView.tsx+++ b/libs/components/editor-blocks/src/blocks/text/TextView.tsx@@ -211,7 +211,7 @@ export const TextView = ({block.firstCreateFlag = true;};const onTab: TextProps['handleTab'] = async ({ isShiftKey }) => {- await tabBlock(block, isShiftKey);+ await tabBlock(editor, block, isShiftKey);return true;};diff --git a/libs/components/editor-blocks/src/blocks/todo/TodoView.tsx b/libs/components/editor-blocks/src/blocks/todo/TodoView.tsxindex 961aa92735..8982f4695e 100644--- a/libs/components/editor-blocks/src/blocks/todo/TodoView.tsx+++ b/libs/components/editor-blocks/src/blocks/todo/TodoView.tsx@@ -100,7 +100,7 @@ export const TodoView = ({ block, editor }: CreateView) => {};const on_tab: TextProps['handleTab'] = async ({ isShiftKey }) => {- await tabBlock(block, isShiftKey);+ await tabBlock(editor, block, isShiftKey);return true;};diff --git a/libs/components/editor-blocks/src/utils/indent.ts b/libs/components/editor-blocks/src/utils/indent.tsindex a68dd5b2db..7f0a2bad08 100644--- a/libs/components/editor-blocks/src/utils/indent.ts+++ b/libs/components/editor-blocks/src/utils/indent.ts@@ -1,4 +1,7 @@-import { supportChildren } from '@toeverything/components/editor-core';+import {+ type BlockEditor,+ supportChildren,+} from '@toeverything/components/editor-core';import { Protocol } from '@toeverything/datasource/db-service';import { AsyncBlock } from '@toeverything/framework/virgo';import type { TodoAsyncBlock } from '../blocks/todo/types';@@ -6,14 +9,19 @@ import type { TodoAsyncBlock } from '../blocks/todo/types';/*** Is the block in top level*/-export const isTopLevelBlock = (parentBlock: AsyncBlock): boolean => {+export const isTopLevelBlock = (+ editor: BlockEditor,+ block: AsyncBlock+): boolean => {return (- parentBlock.type === Protocol.Block.Type.group ||- parentBlock.type === Protocol.Block.Type.page+ editor.getRootBlockId() === block.id ||+ block.type === Protocol.Block.Type.group ||+ block.type === Protocol.Block.Type.page);};/**+ * Move down* @returns true if indent is success* @example* ```@@ -31,7 +39,6 @@ export const isTopLevelBlock = (parentBlock: AsyncBlock): boolean => {* ```*/const indentBlock = async (block: TodoAsyncBlock) => {- // Move downconst previousBlock = await block.previousSibling();if (!previousBlock || !supportChildren(previousBlock)) {@@ -57,6 +64,7 @@ const indentBlock = async (block: TodoAsyncBlock) => {};/**+ * Move up* @returns true if dedent is success* @example* ```@@ -73,13 +81,15 @@ const indentBlock = async (block: TodoAsyncBlock) => {* └─ [ ]* ```*/-const dedentBlock = async (block: AsyncBlock) => {- // Move up+const dedentBlock = async (editor: BlockEditor, block: AsyncBlock) => {+ if (editor.getRootBlockId() === block.id) {+ return false;+ }let parentBlock = await block.parent();if (!parentBlock) {throw new Error('Failed to dedent block! Parent block not found!');}- if (isTopLevelBlock(parentBlock)) {+ if (isTopLevelBlock(editor, parentBlock)) {// Top, do nothingreturn false;}@@ -111,9 +121,13 @@ const dedentBlock = async (block: AsyncBlock) => {return true;};-export const tabBlock = async (block: AsyncBlock, isShiftKey: boolean) => {+export const tabBlock = async (+ editor: BlockEditor,+ block: AsyncBlock,+ isShiftKey: boolean+) => {if (isShiftKey) {- return await dedentBlock(block);+ return await dedentBlock(editor, block);} else {return await indentBlock(block);}