fix: do not check for node selection within posToDOMRect

This commit is contained in:
Philipp Kühn 2021-05-24 20:40:24 +02:00
parent 3bb99b8e1e
commit c0e68d5a25
2 changed files with 12 additions and 11 deletions

View File

@ -1,16 +1,7 @@
import isNodeSelection from './isNodeSelection'
import { EditorView } from 'prosemirror-view'
import coordsAtPos from './coordsAtPos'
export default function posToDOMRect(view: EditorView, from: number, to: number): DOMRect {
if (isNodeSelection(view.state.selection)) {
const node = view.nodeDOM(from) as HTMLElement
if (node && node.getBoundingClientRect) {
return node.getBoundingClientRect()
}
}
const start = coordsAtPos(view, from)
const end = coordsAtPos(view, to, true)
const top = Math.min(start.top, end.top)

View File

@ -1,4 +1,4 @@
import { Editor, posToDOMRect } from '@tiptap/core'
import { Editor, posToDOMRect, isNodeSelection } from '@tiptap/core'
import { EditorState, Plugin, PluginKey } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import tippy, { Instance, Props } from 'tippy.js'
@ -104,7 +104,17 @@ export class BubbleMenuView {
}
this.tippy.setProps({
getReferenceClientRect: () => posToDOMRect(view, from, to),
getReferenceClientRect: () => {
if (isNodeSelection(view.state.selection)) {
const node = view.nodeDOM(from) as HTMLElement
if (node) {
return node.getBoundingClientRect()
}
}
return posToDOMRect(view, from, to)
},
})
this.show()