editor: Open link toolbar automatically when editable and link in selection

This commit is contained in:
Tom Moor
2022-02-11 18:34:56 -08:00
parent 2dd86bbc2b
commit 4255dd24da
2 changed files with 12 additions and 36 deletions

View File

@@ -40,14 +40,14 @@ type Props = {
view: EditorView;
};
function isVisible(props: Props) {
function isVisible(props: Props, link: boolean) {
const { view } = props;
const { selection } = view.state;
if (!selection) {
return false;
if (link) {
return true;
}
if (selection.empty) {
if (!selection || selection.empty) {
return false;
}
if (selection instanceof NodeSelection && selection.node.type.name === "hr") {
@@ -232,14 +232,14 @@ export default class SelectionToolbar extends React.Component<Props> {
state.selection.to
).textContent;
if (isTextSelection && !selectionText) {
if (isTextSelection && !selectionText && !link) {
return null;
}
return (
<FloatingToolbar
view={view}
active={isVisible(this.props)}
active={isVisible(this.props, link)}
ref={this.menuRef}
>
{link && range ? (