fix: rich text link with no selection

This commit is contained in:
Elliot DeNolf
2022-09-09 15:17:51 -07:00
parent 48f0c06edc
commit 5a19f6915a
2 changed files with 5 additions and 3 deletions

View File

@@ -68,7 +68,7 @@ export const LinkButton = ({ fieldProps }) => {
if (!isCollapsed) {
const data = {
text: Editor.string(editor, editor.selection),
text: editor.selection ? Editor.string(editor, editor.selection) : '',
};
const state = await buildStateFromSchema({ fieldSchema, data, user, operation: 'create', locale });
@@ -102,14 +102,14 @@ export const LinkButton = ({ fieldProps }) => {
children: [],
};
if (isCollapsed) {
if (isCollapsed || !editor.selection) {
// If selection anchor and focus are the same,
// Just inject a new node with children already set
Transforms.insertNodes(editor, {
...newLink,
children: [{ text: String(data.text) }],
});
} else {
} else if (editor.selection) {
// Otherwise we need to wrap the selected node in a link,
// Delete its old text,
// Move the selection one position forward into the link,

View File

@@ -169,6 +169,7 @@ export const LinkElement = ({ attributes, children, element, editorRef, fieldPro
</a>
)}
<Button
className={`${baseClass}__link-edit`}
icon="edit"
round
buttonStyle="icon-label"
@@ -181,6 +182,7 @@ export const LinkElement = ({ attributes, children, element, editorRef, fieldPro
tooltip="Edit"
/>
<Button
className={`${baseClass}__link-close`}
icon="x"
round
buttonStyle="icon-label"