Files
AFFiNE-Mirror/blocksuite/affine/blocks/paragraph/src/commands/append-paragraph.ts
T
Saul-Mirone 1f45cc5dec 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`
2025-04-07 12:34:40 +00:00

31 lines
766 B
TypeScript

import { focusTextModel } from '@blocksuite/affine-rich-text';
import { getLastNoteBlock } from '@blocksuite/affine-shared/utils';
import type { Command } from '@blocksuite/std';
import { Text } from '@blocksuite/store';
/**
* Append a paragraph block at the end of the whole page.
*/
export const appendParagraphCommand: Command<{ text?: string }> = (
ctx,
next
) => {
const { std, text = '' } = ctx;
const { store } = std;
if (!store.root) return;
const note = getLastNoteBlock(store);
let noteId = note?.id;
if (!noteId) {
noteId = store.addBlock('affine:note', {}, store.root.id);
}
const id = store.addBlock(
'affine:paragraph',
{ text: new Text(text) },
noteId
);
focusTextModel(std, id, text.length);
next();
};