mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-23 03:51:38 +03:00
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:
parent
08408bf51d
commit
4625d8463e
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user