Skip to content

Commit

Permalink
fix: show FloatingMenu by default only if focused
Browse files Browse the repository at this point in the history
  • Loading branch information
jaulz authored Dec 14, 2021
1 parent 9e6fbd6 commit 29563bb
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 29563bb

Please sign in to comment.