mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-09 13:15:51 +08:00
17bf75e843
Closes: [BS-2216](https://linear.app/affine-design/issue/BS-2216/remove-global-types-in-command)
31 lines
783 B
TypeScript
31 lines
783 B
TypeScript
import { focusTextModel } from '@blocksuite/affine-components/rich-text';
|
|
import { getLastNoteBlock } from '@blocksuite/affine-shared/utils';
|
|
import type { Command } from '@blocksuite/block-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();
|
|
};
|