mirror of https://github.com/fantasticit/think.git
fix: use parentNode rect first
parent
c50a520529
commit
b14833c79f
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue