fix: rich text link with no selection
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user