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/group select (#378)

Chi Zhang4625d8463ed2
diff --git a/libs/components/editor-blocks/src/components/text-manage/TextManage.tsx b/libs/components/editor-blocks/src/components/text-manage/TextManage.tsx
index 72faaef8a7..4b32a9da43 100644
--- a/libs/components/editor-blocks/src/components/text-manage/TextManage.tsx
+++ b/libs/components/editor-blocks/src/components/text-manage/TextManage.tsx
@@ -6,7 +6,10 @@ import {
} from '@toeverything/components/common';
import { useOnSelectActive } from '@toeverything/components/editor-core';
import { styled } from '@toeverything/components/ui';
-import { ContentColumnValue } from '@toeverything/datasource/db-service';
+import {
+ ContentColumnValue,
+ Protocol,
+} from '@toeverything/datasource/db-service';
import {
AsyncBlock,
BlockEditor,
@@ -377,9 +380,36 @@ export const TextManage = forwardRef<ExtendedTextUtils, CreateTextView>(
return false;
}
};
- const onSelectAll = () => {
+ const selectGroupBlocks = async (isSelectAll: boolean) => {
+ if (editor.selectionManager.currentSelectInfo.anchorNode) {
+ const block = await editor.getBlockById(
+ editor.selectionManager.currentSelectInfo.anchorNode.id
+ );
+ if (isSelectAll) {
+ if (
+ Protocol.Block.Type.group !== block.type &&
+ Protocol.Block.Type.page !== block.type
+ ) {
+ const paths = await editor.getBlockPath(block.id);
+ paths &&
+ paths[1] &&
+ editor.selectionManager.setSelectedNodesIds([
+ paths[1].id,
+ ]);
+ return true;
+ }
+ }
+ }
+ };
+ const onSelectAll = async () => {
const isSelectAll =
textRef.current.isEmpty() || textRef.current.isSelectAll();
+
+ const ifSelectGroup = await selectGroupBlocks(isSelectAll);
+ if (ifSelectGroup) {
+ return false;
+ }
+
if (isSelectAll) {
editor.selectionManager.selectAllBlocks();
return true;
diff --git a/libs/components/editor-core/src/editor/selection/selection.ts b/libs/components/editor-core/src/editor/selection/selection.ts
index c33eb6d64c..74005c728b 100644
--- a/libs/components/editor-core/src/editor/selection/selection.ts
+++ b/libs/components/editor-core/src/editor/selection/selection.ts
@@ -256,6 +256,7 @@ export class SelectionManager implements VirgoSelection {
const rootBlockId = this._editor.getRootBlockId();
const rootBlock = await this._editor.getBlockById(rootBlockId);
const children = await rootBlock?.children();
+
if (children) {
this.setSelectedNodesIds(children.map(({ id }) => id));
// blur focused element and blur it
diff --git a/libs/components/editor-plugins/src/menu/inline-menu/menu-item/IconItem.tsx b/libs/components/editor-plugins/src/menu/inline-menu/menu-item/IconItem.tsx
index bd3a13bf8d..981fcd7418 100644
--- a/libs/components/editor-plugins/src/menu/inline-menu/menu-item/IconItem.tsx
+++ b/libs/components/editor-plugins/src/menu/inline-menu/menu-item/IconItem.tsx
@@ -2,7 +2,11 @@ import { Tooltip } from '@toeverything/components/ui';
import { uaHelper } from '@toeverything/utils';
import React, { useCallback } from 'react';
import style9 from 'style9';
-import { inlineMenuNamesKeys, WinInlineMenuShortcuts } from '../config';
+import {
+ inlineMenuNamesKeys,
+ MacInlineMenuShortcuts,
+ WinInlineMenuShortcuts,
+} from '../config';
import type { IconItemType, WithEditorSelectionType } from '../types';
type MenuIconItemProps = IconItemType & WithEditorSelectionType;