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:
yoyoyohamapi
2025-03-14 02:35:20 +00:00
parent d936553047
commit aa15b106d9
4 changed files with 104 additions and 0 deletions

View File

@@ -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;
}