mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 05:47:09 +08:00
feat(editor): add start-with-ai button for empty doc (#9836)
Close [BS-2391](https://linear.app/affine-design/issue/BS-2391/bs-ai-toolbar-空状态下添加-actions-列表) https://github.com/user-attachments/assets/cbded517-2d3d-4a75-b144-644e2b03f68a
This commit is contained in:
@@ -117,14 +117,16 @@ export class PageRootBlockComponent extends BlockComponent<
|
||||
/**
|
||||
* Focus the first paragraph in the default note block.
|
||||
* If there is no paragraph, create one.
|
||||
* @return { id: string, created: boolean } id of the focused paragraph and whether it is created or not
|
||||
*/
|
||||
focusFirstParagraph = () => {
|
||||
focusFirstParagraph = (): { id: string; created: boolean } => {
|
||||
const defaultNote = this._getDefaultNoteBlock();
|
||||
const firstText = defaultNote?.children.find(block =>
|
||||
matchFlavours(block, ['affine:paragraph', 'affine:list', 'affine:code'])
|
||||
);
|
||||
if (firstText) {
|
||||
focusTextModel(this.std, firstText.id);
|
||||
return { id: firstText.id, created: false };
|
||||
} else {
|
||||
const newFirstParagraphId = this.doc.addBlock(
|
||||
'affine:paragraph',
|
||||
@@ -133,6 +135,7 @@ export class PageRootBlockComponent extends BlockComponent<
|
||||
0
|
||||
);
|
||||
focusTextModel(this.std, newFirstParagraphId);
|
||||
return { id: newFirstParagraphId, created: true };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user