mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 10:52:40 +08:00
feat(editor): content block getter command (#10720)
### TL;DR Added new commands to retrieve the first and last content blocks in a document. ### What changed? - Created `getFirstContentBlockCommand` to find the first content block in a document - Created `getLastContentBlockCommand` to find the last content block in a document - Added `getFirstNoteBlock` utility function to find the first note block in a document
This commit is contained in:
@@ -57,3 +57,19 @@ export function getLastNoteBlock(doc: Store) {
|
||||
}
|
||||
return note;
|
||||
}
|
||||
|
||||
export function getFirstNoteBlock(doc: Store) {
|
||||
let note: NoteBlockModel | null = null;
|
||||
if (!doc.root) return null;
|
||||
const { children } = doc.root;
|
||||
for (const child of children) {
|
||||
if (
|
||||
matchModels(child, [NoteBlockModel]) &&
|
||||
child.displayMode !== NoteDisplayMode.EdgelessOnly
|
||||
) {
|
||||
note = child as NoteBlockModel;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return note;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user