From ec748f9914551e3a5d4302b3fd287af2f84d03dd Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 21 May 2022 12:57:29 +0100 Subject: [PATCH] fix: Floating toolbar should not appear until mouseup when selecting with mouse closes #3564 --- app/editor/components/SelectionToolbar.tsx | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/app/editor/components/SelectionToolbar.tsx b/app/editor/components/SelectionToolbar.tsx index 42ef3c76d..ad6e80c59 100644 --- a/app/editor/components/SelectionToolbar.tsx +++ b/app/editor/components/SelectionToolbar.tsx @@ -42,7 +42,7 @@ type Props = { function isVisible(props: Props) { const { view } = props; - const { selection } = view.state; + const { selection, doc } = view.state; if (isMarkActive(view.state.schema.marks.link)(view.state)) { return true; @@ -63,6 +63,11 @@ function isVisible(props: Props) { return false; } + const selectionText = doc.cut(selection.from, selection.to).textContent; + if (selection instanceof TextSelection && !selectionText) { + return false; + } + const slice = selection.content(); const fragment = slice.content; const nodes = (fragment as any).content; @@ -192,7 +197,6 @@ export default class SelectionToolbar extends React.Component { const link = isMarkActive(state.schema.marks.link)(state); const range = getMarkRange(selection.$from, state.schema.marks.link); const isImageSelection = selection.node?.type?.name === "image"; - let isTextSelection = false; let items: MenuItem[] = []; if (isTableSelection) { @@ -207,7 +211,6 @@ export default class SelectionToolbar extends React.Component { items = getDividerMenuItems(state, dictionary); } else { items = getFormattingMenuItems(state, isTemplate, dictionary); - isTextSelection = true; } // Some extensions may be disabled, remove corresponding items @@ -226,15 +229,6 @@ export default class SelectionToolbar extends React.Component { return null; } - const selectionText = state.doc.cut( - state.selection.from, - state.selection.to - ).textContent; - - if (isTextSelection && !selectionText && !link) { - return null; - } - return (