mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 03:56:23 +08:00
1f45cc5dec
**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`
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { NoteBlockModel } from '@blocksuite/affine-model';
|
|
import { matchModels } from '@blocksuite/affine-shared/utils';
|
|
import { type Command, TextSelection } from '@blocksuite/std';
|
|
|
|
import { dedentBlockToRoot } from './dedent-block-to-root';
|
|
|
|
export const dedentBlocksToRoot: Command<{
|
|
blockIds?: string[];
|
|
stopCapture?: boolean;
|
|
}> = (ctx, next) => {
|
|
let { blockIds } = ctx;
|
|
const { std, stopCapture = true } = ctx;
|
|
const { store } = std;
|
|
if (!blockIds || !blockIds.length) {
|
|
const text = std.selection.find(TextSelection);
|
|
if (text) {
|
|
// If the text selection is not at the beginning of the block, use default behavior
|
|
if (text.from.index !== 0) return;
|
|
|
|
blockIds = [text.from.blockId, text.to?.blockId].filter(
|
|
(x): x is string => !!x
|
|
);
|
|
} else {
|
|
blockIds = std.selection.getGroup('note').map(sel => sel.blockId);
|
|
}
|
|
}
|
|
|
|
if (!blockIds || !blockIds.length || store.readonly) return;
|
|
|
|
if (stopCapture) store.captureSync();
|
|
for (let i = blockIds.length - 1; i >= 0; i--) {
|
|
const model = blockIds[i];
|
|
const parent = store.getParent(model);
|
|
if (parent && !matchModels(parent, [NoteBlockModel])) {
|
|
std.command.exec(dedentBlockToRoot, {
|
|
blockId: model,
|
|
stopCapture: false,
|
|
});
|
|
}
|
|
}
|
|
|
|
return next();
|
|
};
|