* Fixed #2734

* Prettified Code!

---------

Co-authored-by: bennett1412 <bennett1412@users.noreply.github.com>
This commit is contained in:
Bennett B Madavana
2023-02-27 07:39:24 +05:30
committed by GitHub
parent 5a76d3e62c
commit 5e155179ef

View File

@@ -169,31 +169,10 @@ export const ChatTextField: FC<ChatTextFieldProps> = ({ defaultText }) => {
const insertImage = (url, name) => { const insertImage = (url, name) => {
if (!url) return; if (!url) return;
const { selection } = editor;
const image = createImageNode(name, url, name); const image = createImageNode(name, url, name);
Transforms.insertNodes(editor, image, { select: true }); Transforms.insertNodes(editor, image);
Editor.normalize(editor, { force: true });
if (selection) {
const [parentNode, parentPath] = Editor.parent(editor, selection.focus?.path);
if (editor.isVoid(parentNode) || Node.string(parentNode).length) {
// Insert the new image node after the void node or a node with content
Transforms.insertNodes(editor, image, {
at: Path.next(parentPath),
select: true,
});
} else {
// If the node is empty, replace it instead
// Transforms.removeNodes(editor, { at: parentPath });
Transforms.insertNodes(editor, image, { at: parentPath, select: true });
Editor.normalize(editor, { force: true });
}
} else {
// Insert the new image node at the bottom of the Editor when selection
// is falsey
Transforms.insertNodes(editor, image, { select: true });
}
}; };
// Native emoji // Native emoji