fix: use parentNode rect first

pull/8/head
fantasticit 2022-03-22 13:37:14 +08:00
parent c50a520529
commit b14833c79f
1 changed files with 6 additions and 16 deletions

View File

@ -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<FloatMenuViewOptions['getReferenceClientRect']> = ({
editor,
range,
}) => {
private getReferenceClientRect: NonNullable<FloatMenuViewOptions['getReferenceClientRect']> = ({ 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);
};