From 4ad58b4ccd6ef234dba2ef3d8d1c3e18ab7fccbf Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 23 Feb 2025 11:00:42 -0500 Subject: [PATCH] fix: Incorrect menu position when notice is first item in doc, closes #8539 --- app/editor/components/FloatingToolbar.tsx | 2 +- app/editor/menus/notice.tsx | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/editor/components/FloatingToolbar.tsx b/app/editor/components/FloatingToolbar.tsx index df7bc2177e..af198da950 100644 --- a/app/editor/components/FloatingToolbar.tsx +++ b/app/editor/components/FloatingToolbar.tsx @@ -89,7 +89,7 @@ function usePosition({ ? noticeBlock.pos : null; - if (position) { + if (position !== null) { const element = view.nodeDOM(position); const bounds = (element as HTMLElement).getBoundingClientRect(); selectionBounds.top = bounds.top; diff --git a/app/editor/menus/notice.tsx b/app/editor/menus/notice.tsx index 3ef1c8b71a..a1125c6b80 100644 --- a/app/editor/menus/notice.tsx +++ b/app/editor/menus/notice.tsx @@ -16,10 +16,8 @@ export default function noticeMenuItems( readOnly: boolean | undefined, dictionary: Dictionary ): MenuItem[] { - const { selection } = state; - const { $from } = selection; - const node = $from.node(-1); - const currentStyle = node.attrs.style as NoticeTypes; + const node = state.selection.$from.node(-1); + const currentStyle = node?.attrs.style as NoticeTypes; const mapping = { [NoticeTypes.Info]: dictionary.infoNotice,