Skip to content

Commit

Permalink
fix: show FloatingMenu by default only if focused (#2275)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaulz authored Dec 15, 2021
1 parent 0e0cdc0 commit 809af3b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/extension-floating-menu/src/floating-menu-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ export class FloatingMenuView {

public tippyOptions?: Partial<Props>

public shouldShow: Exclude<FloatingMenuPluginProps['shouldShow'], null> = ({ state }) => {
public shouldShow: Exclude<FloatingMenuPluginProps['shouldShow'], null> = ({ state, view }) => {
const { selection } = state
const { $anchor, empty } = selection
const isRootDepth = $anchor.depth === 1
const isEmptyTextBlock = $anchor.parent.isTextblock
&& !$anchor.parent.type.spec.code
&& !$anchor.parent.textContent

if (!view.hasFocus()) {
return false
}

if (!empty || !isRootDepth || !isEmptyTextBlock) {
return false
}
Expand Down

0 comments on commit 809af3b

Please sign in to comment.