Skip to content

Commit

Permalink
Make HTMLEditor::InsertElementAtSelectionAsAction split ancestor in…
Browse files Browse the repository at this point in the history
…line elements

Chrome and Safari splits ancestors when `document.execCommand("insertImage")`
 inserts an `<img>`, but we insert into the closest inline element. For example,
```html
<b>A[]B</b>
```
Chrome and Safari make it to:
```html
<b>A</b><img><b>B</b>
```
But Firefox makes it to:
```html
<b>A<img>B</b>
```
I think that we should not change the behavior on Thunderbird.  Therefore, the
behavior is controlled with the new `options` argument and the new behavior
runs only when the `HTMLEditor` works for content document and it's not caused
by the XPCOM method.

Differential Revision: https://phabricator.services.mozilla.com/D225037

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1923250
gecko-commit: 4d82c0995e5d5653017d08b4c101f078a165039c
gecko-reviewers: m_kato
  • Loading branch information
masayuki-nakano authored and moz-wptsync-bot committed Oct 12, 2024
1 parent 5611c15 commit 38a8c54
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions editing/data/insertimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var browserTests = [
{"insertimage":[false,false,"",false,false,""]}],
["<span>foo[</span><span>]bar</span>",
[["insertimage","/img/lion.svg"]],
"<span>foo<img src=\"/img/lion.svg\">{}</span><span>bar</span>",
"<span>foo</span><img src=\"/img/lion.svg\"><span>bar</span>",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["foo[bar]baz",
Expand All @@ -27,17 +27,17 @@ var browserTests = [
{"insertimage":[false,false,"",false,false,""]}],
["foo<span style=color:#aBcDeF>[bar]</span>baz",
[["insertimage","/img/lion.svg"]],
"foo<span style=\"color:rgb(171, 205, 239)\"><img src=\"/img/lion.svg\">{}</span>baz",
"foo<img src=\"/img/lion.svg\">baz",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["foo<span style=color:#aBcDeF>{bar}</span>baz",
[["insertimage","/img/lion.svg"]],
"foo<span style=\"color:rgb(171, 205, 239)\"><img src=\"/img/lion.svg\">{}</span>baz",
"foo<img src=\"/img/lion.svg\">baz",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["foo{<span style=color:#aBcDeF>bar</span>}baz",
[["insertimage","/img/lion.svg"]],
"foo<span style=\"color:rgb(171, 205, 239)\"><img src=\"/img/lion.svg\">{}</span>baz",
"foo<img src=\"/img/lion.svg\">baz",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["[foo<span style=color:#aBcDeF>bar]</span>baz",
Expand All @@ -62,57 +62,57 @@ var browserTests = [
{"stylewithcss":[false,true,"",false,false,""],"insertimage":[false,false,"",false,false,""]}],
["foo<span style=color:#aBcDeF>[bar</span>baz]",
[["insertimage","/img/lion.svg"]],
"foo<span style=\"color:rgb(171, 205, 239)\"><img src=\"/img/lion.svg\">{}</span>",
"foo<img src=\"/img/lion.svg\">",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["foo<span style=color:#aBcDeF>{bar</span>baz}",
[["insertimage","/img/lion.svg"]],
"foo<span style=\"color:rgb(171, 205, 239)\"><img src=\"/img/lion.svg\">{}</span>",
"foo<img src=\"/img/lion.svg\">",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["foo<span style=color:#aBcDeF>[bar</span><span style=color:#fEdCbA>baz]</span>quz",
[["stylewithcss","true"],["insertimage","/img/lion.svg"]],
"foo<span style=\"color:rgb(171, 205, 239)\"><img src=\"/img/lion.svg\">{}</span>quz",
"foo<img src=\"/img/lion.svg\">quz",
[true,true],
{"stylewithcss":[false,false,"",false,true,""],"insertimage":[false,false,"",false,false,""]}],
["foo<span style=color:#aBcDeF>[bar</span><span style=color:#fEdCbA>baz]</span>quz",
[["stylewithcss","false"],["insertimage","/img/lion.svg"]],
"foo<span style=\"color:rgb(171, 205, 239)\"><img src=\"/img/lion.svg\">{}</span>quz",
"foo<img src=\"/img/lion.svg\">quz",
[true,true],
{"stylewithcss":[false,true,"",false,false,""],"insertimage":[false,false,"",false,false,""]}],
["foo<b>[bar]</b>baz",
[["insertimage","/img/lion.svg"]],
"foo<b><img src=\"/img/lion.svg\">{}</b>baz",
"foo<img src=\"/img/lion.svg\">baz",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["foo<b>{bar}</b>baz",
[["insertimage","/img/lion.svg"]],
"foo<b><img src=\"/img/lion.svg\">{}</b>baz",
"foo<img src=\"/img/lion.svg\">baz",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["foo{<b>bar</b>}baz",
[["insertimage","/img/lion.svg"]],
"foo<b><img src=\"/img/lion.svg\">{}</b>baz",
"foo<img src=\"/img/lion.svg\">baz",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["foo<span>[bar]</span>baz",
[["insertimage","/img/lion.svg"]],
"foo<span><img src=\"/img/lion.svg\">{}</span>baz",
"foo<img src=\"/img/lion.svg\">baz",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["foo<span>{bar}</span>baz",
[["insertimage","/img/lion.svg"]],
"foo<span><img src=\"/img/lion.svg\">{}</span>baz",
"foo<img src=\"/img/lion.svg\">baz",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["foo{<span>bar</span>}baz",
[["insertimage","/img/lion.svg"]],
"foo<span><img src=\"/img/lion.svg\">{}</span>baz",
"foo<img src=\"/img/lion.svg\">baz",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["<b>foo[bar</b><i>baz]quz</i>",
[["insertimage","/img/lion.svg"]],
"<b>foo<img src=\"/img/lion.svg\">{}</b><i>quz</i>",
"<b>foo</b><img src=\"/img/lion.svg\"><i>quz</i>",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["<p>foo</p><p>[bar]</p><p>baz</p>",
Expand Down Expand Up @@ -355,4 +355,32 @@ var browserTests = [
"foo<img src=\"/\u65E5\u672C\u8A9E\u30D1\u30B9/lion.svg\">{}bar",
[true],
{"insertimage":[false,false,"",false,false,""]}],
["<div>{}<br></div>",
[["insertimage","/img/lion.svg"]],
["<div><img src=\"/img/lion.svg\"></div>",
"<div><img src=\"/img/lion.svg\"><br></div>"],
[true],
{}],
["<div><b>{}<br></b></div>",
[["insertimage","/img/lion.svg"]],
["<div><img src=\"/img/lion.svg\"></div>",
"<div><img src=\"/img/lion.svg\"><b><br></b></div>"],
[true],
{}],
["<div><span>{}<br></span></div>",
[["insertimage","/img/lion.svg"]],
["<div><img src=\"/img/lion.svg\"></div>",
"<div><img src=\"/img/lion.svg\"><span><br></span></div>"],
[true],
{}],
["<div><b>A[]B</b></div>",
[["insertimage","/img/lion.svg"]],
"<div><b>A</b><img src=\"/img/lion.svg\"><b>B</b></div>",
[true],
{}],
["<div><span>A[]B</span></div>",
[["insertimage","/img/lion.svg"]],
"<div><span>A</span><img src=\"/img/lion.svg\"><span>B</span></div>",
[true],
{}],
]

0 comments on commit 38a8c54

Please sign in to comment.