fix: Floating toolbar should not appear until mouseup when selecting with mouse

closes #3564
This commit is contained in:
Tom Moor
2022-05-21 12:57:29 +01:00
parent ef668c2fa0
commit ec748f9914

View File

@@ -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<Props> {
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<Props> {
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<Props> {
return null;
}
const selectionText = state.doc.cut(
state.selection.from,
state.selection.to
).textContent;
if (isTextSelection && !selectionText && !link) {
return null;
}
return (
<FloatingToolbar
view={view}