mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-07 17:43:49 +08:00
refactoring
This commit is contained in:
parent
809af3b6c6
commit
1645df9adc
@ -40,7 +40,12 @@ export class BubbleMenuView {
|
|||||||
|
|
||||||
public tippyOptions?: Partial<Props>
|
public tippyOptions?: Partial<Props>
|
||||||
|
|
||||||
public shouldShow: Exclude<BubbleMenuPluginProps['shouldShow'], null> = ({ state, from, to }) => {
|
public shouldShow: Exclude<BubbleMenuPluginProps['shouldShow'], null> = ({
|
||||||
|
view,
|
||||||
|
state,
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
}) => {
|
||||||
const { doc, selection } = state
|
const { doc, selection } = state
|
||||||
const { empty } = selection
|
const { empty } = selection
|
||||||
|
|
||||||
@ -50,7 +55,11 @@ export class BubbleMenuView {
|
|||||||
const isEmptyTextBlock = !doc.textBetween(from, to).length
|
const isEmptyTextBlock = !doc.textBetween(from, to).length
|
||||||
&& isTextSelection(state.selection)
|
&& isTextSelection(state.selection)
|
||||||
|
|
||||||
if (empty || isEmptyTextBlock) {
|
if (
|
||||||
|
!view.hasFocus()
|
||||||
|
|| empty
|
||||||
|
|| isEmptyTextBlock
|
||||||
|
) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ export class FloatingMenuView {
|
|||||||
|
|
||||||
public tippyOptions?: Partial<Props>
|
public tippyOptions?: Partial<Props>
|
||||||
|
|
||||||
public shouldShow: Exclude<FloatingMenuPluginProps['shouldShow'], null> = ({ state, view }) => {
|
public shouldShow: Exclude<FloatingMenuPluginProps['shouldShow'], null> = ({ view, state }) => {
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
const { $anchor, empty } = selection
|
const { $anchor, empty } = selection
|
||||||
const isRootDepth = $anchor.depth === 1
|
const isRootDepth = $anchor.depth === 1
|
||||||
@ -41,11 +41,12 @@ export class FloatingMenuView {
|
|||||||
&& !$anchor.parent.type.spec.code
|
&& !$anchor.parent.type.spec.code
|
||||||
&& !$anchor.parent.textContent
|
&& !$anchor.parent.textContent
|
||||||
|
|
||||||
if (!view.hasFocus()) {
|
if (
|
||||||
return false
|
!view.hasFocus()
|
||||||
}
|
|| !empty
|
||||||
|
|| !isRootDepth
|
||||||
if (!empty || !isRootDepth || !isEmptyTextBlock) {
|
|| !isEmptyTextBlock
|
||||||
|
) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user