mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 06:18:45 +08:00
refactor(editor): unify directories naming (#11516)
**Directory Structure Changes** - Renamed multiple block-related directories by removing the "block-" prefix: - `block-attachment` → `attachment` - `block-bookmark` → `bookmark` - `block-callout` → `callout` - `block-code` → `code` - `block-data-view` → `data-view` - `block-database` → `database` - `block-divider` → `divider` - `block-edgeless-text` → `edgeless-text` - `block-embed` → `embed`
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import {
|
||||
AttachmentBlockModel,
|
||||
BookmarkBlockModel,
|
||||
CalloutBlockModel,
|
||||
CodeBlockModel,
|
||||
DatabaseBlockModel,
|
||||
DividerBlockModel,
|
||||
ImageBlockModel,
|
||||
ListBlockModel,
|
||||
ParagraphBlockModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { EMBED_BLOCK_MODEL_LIST } from '@blocksuite/affine-shared/consts';
|
||||
import {
|
||||
getNextContentBlock,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
BlockSelection,
|
||||
type BlockStdScope,
|
||||
TextSelection,
|
||||
} from '@blocksuite/std';
|
||||
|
||||
export function forwardDelete(std: BlockStdScope) {
|
||||
const { store, host } = std;
|
||||
const text = std.selection.find(TextSelection);
|
||||
if (!text) return;
|
||||
const isCollapsed = text.isCollapsed();
|
||||
const model = store.getBlock(text.from.blockId)?.model;
|
||||
if (
|
||||
!model ||
|
||||
!matchModels(model, [ParagraphBlockModel]) ||
|
||||
matchModels(model.parent, [CalloutBlockModel])
|
||||
)
|
||||
return;
|
||||
const isEnd = isCollapsed && text.from.index === model.props.text.length;
|
||||
if (!isEnd) return;
|
||||
const parent = store.getParent(model);
|
||||
if (!parent) return;
|
||||
|
||||
const nextSibling = store.getNext(model);
|
||||
|
||||
if (
|
||||
matchModels(nextSibling, [
|
||||
AttachmentBlockModel,
|
||||
BookmarkBlockModel,
|
||||
DatabaseBlockModel,
|
||||
CodeBlockModel,
|
||||
ImageBlockModel,
|
||||
DividerBlockModel,
|
||||
...EMBED_BLOCK_MODEL_LIST,
|
||||
] as const)
|
||||
) {
|
||||
std.selection.setGroup('note', [
|
||||
std.selection.create(BlockSelection, { blockId: nextSibling.id }),
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (matchModels(nextSibling, [ParagraphBlockModel, ListBlockModel])) {
|
||||
model.props.text.join(nextSibling.props.text);
|
||||
if (nextSibling.children) {
|
||||
const parent = store.getParent(nextSibling);
|
||||
if (!parent) return false;
|
||||
store.moveBlocks(nextSibling.children, parent, model, false);
|
||||
}
|
||||
|
||||
store.deleteBlock(nextSibling);
|
||||
return true;
|
||||
}
|
||||
|
||||
const nextBlock = getNextContentBlock(host, model);
|
||||
if (nextBlock?.text) {
|
||||
model.props.text.join(nextBlock.text);
|
||||
if (nextBlock.children) {
|
||||
const parent = store.getParent(nextBlock);
|
||||
if (!parent) return false;
|
||||
store.moveBlocks(
|
||||
nextBlock.children,
|
||||
parent,
|
||||
store.getParent(model),
|
||||
false
|
||||
);
|
||||
}
|
||||
store.deleteBlock(nextBlock);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (nextBlock) {
|
||||
std.selection.setGroup('note', [
|
||||
std.selection.create(BlockSelection, { blockId: nextBlock.id }),
|
||||
]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user