fix: guard editor selection churn around inline actions

This commit is contained in:
lucaronin
2026-04-24 03:25:50 +02:00
parent 24e317cfa6
commit 7c9f2b0dda
3 changed files with 80 additions and 14 deletions

View File

@@ -105,8 +105,23 @@ export function shouldSuppressFormattingToolbarHoverUpdate({
function getActiveFormattingToolbarFileBlockId(
editor: BlockNoteEditor<BlockSchema, InlineContentSchema, StyleSchema>,
) {
const selectedBlock =
editor.getSelection()?.blocks[0] ?? editor.getTextCursorPosition().block
let selectedBlock: ReturnType<typeof editor.getTextCursorPosition>['block'] | null = null
try {
selectedBlock = editor.getSelection()?.blocks[0] ?? null
} catch {
selectedBlock = null
}
if (!selectedBlock) {
try {
selectedBlock = editor.getTextCursorPosition().block
} catch {
selectedBlock = null
}
}
if (!selectedBlock) return null
return FORMATTING_TOOLBAR_FILE_BLOCK_TYPES.has(selectedBlock.type)
? selectedBlock.id