Skip to content

Commit

Permalink
fix: add media would crash if there is no text entered yet
Browse files Browse the repository at this point in the history
  • Loading branch information
kwinyyyc committed Jan 6, 2024
1 parent 515282c commit d0ff5e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions admin/src/components/ReactMdEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,24 @@ const Editor = ({
let newValue = value ? value : "";
assets.map((asset) => {
if (asset.mime.includes("image")) {
const imgTag = ` ![${asset.alt}](${asset.url}) `;
const imgTag = `![${asset.alt}](${asset.url})`;
if (mediaLibSelection > -1) {
newValue =
value.substring(0, mediaLibSelection) +
imgTag +
value.substring(mediaLibSelection);
const preValue = value?.substring(0, mediaLibSelection) ?? "";
const postValue = value?.substring(mediaLibSelection) ?? "";
newValue = `${
preValue && !preValue.endsWith(" ") ? preValue + " " : preValue
}${imgTag}${
postValue && !postValue.startsWith(" ")
? " " + postValue
: postValue
}`;
} else {
newValue = `${newValue}${imgTag}`;
}
}
// Handle videos and other type of files by adding some code
});
onChange({ target: { name, value: newValue || "" } });
onChange({ target: { name, value: newValue ?? "" } });
handleToggleMediaLib();
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "strapi-plugin-wysiwyg-react-md-editor",
"version": "4.4.0",
"version": "4.4.1",
"description": "Replaces the default Strapi WYSIWYG editor with react md editor.",
"strapi": {
"name": "wysiwyg-react-md-editor",
Expand Down

0 comments on commit d0ff5e3

Please sign in to comment.