bubble menu fixes
This commit is contained in:
parent
2e4c9d03d6
commit
283818d12d
|
@ -39,6 +39,7 @@ import { TextBubbleMenu } from './TextBubbleMenu'
|
|||
import { ImageBubbleMenu } from './ImageBubbleMenu'
|
||||
import { EditorFloatingMenu } from './EditorFloatingMenu'
|
||||
import { useEditorContext } from '../../context/editor'
|
||||
import { isTextSelection } from '@tiptap/core'
|
||||
|
||||
type EditorProps = {
|
||||
shoutId: number
|
||||
|
@ -145,15 +146,23 @@ export const Editor = (props: EditorProps) => {
|
|||
pluginKey: 'textBubbleMenu',
|
||||
element: textBubbleMenuRef.current,
|
||||
shouldShow: ({ editor: e, view, state, oldState, from, to }) => {
|
||||
console.log(view)
|
||||
return e.isFocused && !e.isActive('image')
|
||||
const { doc, selection } = state
|
||||
const { empty } = selection
|
||||
|
||||
const isEmptyTextBlock = doc.textBetween(from, to).length === 0 && isTextSelection(selection)
|
||||
|
||||
if (!view.hasFocus() || empty || isEmptyTextBlock || e.isActive('image')) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}),
|
||||
BubbleMenu.configure({
|
||||
pluginKey: 'imageBubbleMenu',
|
||||
element: imageBubbleMenuRef.current,
|
||||
shouldShow: ({ editor: e, view, state, oldState, from, to }) => {
|
||||
return e.isFocused && e.isActive('image')
|
||||
return view.hasFocus() && e.isActive('image')
|
||||
}
|
||||
}),
|
||||
FloatingMenu.configure({
|
||||
|
|
Loading…
Reference in New Issue
Block a user