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 { ImageBubbleMenu } from './ImageBubbleMenu'
|
||||||
import { EditorFloatingMenu } from './EditorFloatingMenu'
|
import { EditorFloatingMenu } from './EditorFloatingMenu'
|
||||||
import { useEditorContext } from '../../context/editor'
|
import { useEditorContext } from '../../context/editor'
|
||||||
|
import { isTextSelection } from '@tiptap/core'
|
||||||
|
|
||||||
type EditorProps = {
|
type EditorProps = {
|
||||||
shoutId: number
|
shoutId: number
|
||||||
|
@ -145,15 +146,23 @@ export const Editor = (props: EditorProps) => {
|
||||||
pluginKey: 'textBubbleMenu',
|
pluginKey: 'textBubbleMenu',
|
||||||
element: textBubbleMenuRef.current,
|
element: textBubbleMenuRef.current,
|
||||||
shouldShow: ({ editor: e, view, state, oldState, from, to }) => {
|
shouldShow: ({ editor: e, view, state, oldState, from, to }) => {
|
||||||
console.log(view)
|
const { doc, selection } = state
|
||||||
return e.isFocused && !e.isActive('image')
|
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({
|
BubbleMenu.configure({
|
||||||
pluginKey: 'imageBubbleMenu',
|
pluginKey: 'imageBubbleMenu',
|
||||||
element: imageBubbleMenuRef.current,
|
element: imageBubbleMenuRef.current,
|
||||||
shouldShow: ({ editor: e, view, state, oldState, from, to }) => {
|
shouldShow: ({ editor: e, view, state, oldState, from, to }) => {
|
||||||
return e.isFocused && e.isActive('image')
|
return view.hasFocus() && e.isActive('image')
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
FloatingMenu.configure({
|
FloatingMenu.configure({
|
||||||
|
|
Loading…
Reference in New Issue
Block a user