Fix/group select (#378)

* fix(select): group selecet

* fix(selection): more robust

* refactor(selection): better group

Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com>
This commit is contained in:
Chi Zhang 2022-09-06 18:12:27 +08:00 committed by GitHub
parent 08408bf51d
commit 4625d8463e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 3 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;