FIX: prevent redirect when image scale btn is inside a link.

Currently in composer preview, if the image scale buttons are inside a `<a>` link then it redirects to the `href` location after the image scaling task.
This commit is contained in:
Vinoth Kannan 2020-07-15 09:34:54 +05:30
parent 5bf0a0893b
commit 0058a15266
2 changed files with 19 additions and 16 deletions

View File

@ -799,22 +799,24 @@ export default Component.extend({
if (matchingPlaceholder) {
const match = matchingPlaceholder[index];
if (!match) {
return;
if (match) {
const replacement = match.replace(
imageScaleRegex,
`![$1|$2, ${scale}%$4]($5)`
);
this.appEvents.trigger(
"composer:replace-text",
matchingPlaceholder[index],
replacement,
{ regex: imageScaleRegex, index }
);
}
const replacement = match.replace(
imageScaleRegex,
`![$1|$2, ${scale}%$4]($5)`
);
this.appEvents.trigger(
"composer:replace-text",
matchingPlaceholder[index],
replacement,
{ regex: imageScaleRegex, index }
);
}
e.preventDefault();
return;
});
},

View File

@ -750,7 +750,7 @@ QUnit.test("Image resizing buttons", async assert => {
let uploads = [
// 0 Default markdown with dimensions- should work
"![test|690x313](upload://test.png)",
"<a href='https://example.com'>![test|690x313](upload://test.png)</a>",
// 1 Image with scaling percentage, should work
"![test|690x313,50%](upload://test.png)",
// 2 image with scaling percentage and a proceeding whitespace, should work
@ -784,7 +784,8 @@ QUnit.test("Image resizing buttons", async assert => {
);
// Default
uploads[0] = "![test|690x313, 50%](upload://test.png)";
uploads[0] =
"<a href='https://example.com'>![test|690x313, 50%](upload://test.png)</a>";
await click(
find(".button-wrapper[data-image-index='0'] .scale-btn[data-scale='50']")
);