From b14833c79f2d3035bd2dcc70ed4b5a1b05eb63ae Mon Sep 17 00:00:00 2001 From: fantasticit Date: Tue, 22 Mar 2022 13:37:14 +0800 Subject: [PATCH] fix: use parentNode rect first --- .../components/tiptap/views/floatMenuView.tsx | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/packages/client/src/components/tiptap/views/floatMenuView.tsx b/packages/client/src/components/tiptap/views/floatMenuView.tsx index 86c4125b..0b17d510 100644 --- a/packages/client/src/components/tiptap/views/floatMenuView.tsx +++ b/packages/client/src/components/tiptap/views/floatMenuView.tsx @@ -5,15 +5,8 @@ import { EditorState } from 'prosemirror-state'; export type FloatMenuViewOptions = { editor: Editor; - getReferenceClientRect?: (props: { - editor: Editor; - range: Range; - oldState?: EditorState; - }) => DOMRect; - shouldShow: ( - props: { editor: Editor; range: Range; oldState?: EditorState }, - instance: FloatMenuView - ) => boolean; + getReferenceClientRect?: (props: { editor: Editor; range: Range; oldState?: EditorState }) => DOMRect; + shouldShow: (props: { editor: Editor; range: Range; oldState?: EditorState }, instance: FloatMenuView) => boolean; init: (dom: HTMLElement, editor: Editor) => void; update?: ( dom: HTMLElement, @@ -36,11 +29,11 @@ export class FloatMenuView { private _update: FloatMenuViewOptions['update']; private shouldShow: FloatMenuViewOptions['shouldShow']; private tippyOptions: FloatMenuViewOptions['tippyOptions']; - private getReferenceClientRect: NonNullable = ({ - editor, - range, - }) => { + private getReferenceClientRect: NonNullable = ({ editor, range }) => { const { view, state } = editor; + if (this.parentNode) { + return this.parentNode.getBoundingClientRect(); + } if (isNodeSelection(state.selection)) { const node = view.nodeDOM(range.from) as HTMLElement; @@ -48,9 +41,6 @@ export class FloatMenuView { return node.getBoundingClientRect(); } } - if (this.parentNode) { - return this.parentNode.getBoundingClientRect(); - } return posToDOMRect(view, range.from, range.to); };