From 38a8c54e7095713f7c290318480c68bb6f2322ef Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Fri, 11 Oct 2024 23:31:29 +0000 Subject: [PATCH] Make `HTMLEditor::InsertElementAtSelectionAsAction` split ancestor inline elements Chrome and Safari splits ancestors when `document.execCommand("insertImage")` inserts an ``, but we insert into the closest inline element. For example, ```html A[]B ``` Chrome and Safari make it to: ```html AB ``` But Firefox makes it to: ```html AB ``` 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 --- editing/data/insertimage.js | 58 +++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/editing/data/insertimage.js b/editing/data/insertimage.js index b18388a7971dfd..b62331e152098e 100644 --- a/editing/data/insertimage.js +++ b/editing/data/insertimage.js @@ -12,7 +12,7 @@ var browserTests = [ {"insertimage":[false,false,"",false,false,""]}], ["foo[]bar", [["insertimage","/img/lion.svg"]], - "foo{}bar", + "foobar", [true], {"insertimage":[false,false,"",false,false,""]}], ["foo[bar]baz", @@ -27,17 +27,17 @@ var browserTests = [ {"insertimage":[false,false,"",false,false,""]}], ["foo[bar]baz", [["insertimage","/img/lion.svg"]], - "foo{}baz", + "foobaz", [true], {"insertimage":[false,false,"",false,false,""]}], ["foo{bar}baz", [["insertimage","/img/lion.svg"]], - "foo{}baz", + "foobaz", [true], {"insertimage":[false,false,"",false,false,""]}], ["foo{bar}baz", [["insertimage","/img/lion.svg"]], - "foo{}baz", + "foobaz", [true], {"insertimage":[false,false,"",false,false,""]}], ["[foobar]baz", @@ -62,57 +62,57 @@ var browserTests = [ {"stylewithcss":[false,true,"",false,false,""],"insertimage":[false,false,"",false,false,""]}], ["foo[barbaz]", [["insertimage","/img/lion.svg"]], - "foo{}", + "foo", [true], {"insertimage":[false,false,"",false,false,""]}], ["foo{barbaz}", [["insertimage","/img/lion.svg"]], - "foo{}", + "foo", [true], {"insertimage":[false,false,"",false,false,""]}], ["foo[barbaz]quz", [["stylewithcss","true"],["insertimage","/img/lion.svg"]], - "foo{}quz", + "fooquz", [true,true], {"stylewithcss":[false,false,"",false,true,""],"insertimage":[false,false,"",false,false,""]}], ["foo[barbaz]quz", [["stylewithcss","false"],["insertimage","/img/lion.svg"]], - "foo{}quz", + "fooquz", [true,true], {"stylewithcss":[false,true,"",false,false,""],"insertimage":[false,false,"",false,false,""]}], ["foo[bar]baz", [["insertimage","/img/lion.svg"]], - "foo{}baz", + "foobaz", [true], {"insertimage":[false,false,"",false,false,""]}], ["foo{bar}baz", [["insertimage","/img/lion.svg"]], - "foo{}baz", + "foobaz", [true], {"insertimage":[false,false,"",false,false,""]}], ["foo{bar}baz", [["insertimage","/img/lion.svg"]], - "foo{}baz", + "foobaz", [true], {"insertimage":[false,false,"",false,false,""]}], ["foo[bar]baz", [["insertimage","/img/lion.svg"]], - "foo{}baz", + "foobaz", [true], {"insertimage":[false,false,"",false,false,""]}], ["foo{bar}baz", [["insertimage","/img/lion.svg"]], - "foo{}baz", + "foobaz", [true], {"insertimage":[false,false,"",false,false,""]}], ["foo{bar}baz", [["insertimage","/img/lion.svg"]], - "foo{}baz", + "foobaz", [true], {"insertimage":[false,false,"",false,false,""]}], ["foo[barbaz]quz", [["insertimage","/img/lion.svg"]], - "foo{}quz", + "fooquz", [true], {"insertimage":[false,false,"",false,false,""]}], ["

foo

[bar]

baz

", @@ -355,4 +355,32 @@ var browserTests = [ "foo{}bar", [true], {"insertimage":[false,false,"",false,false,""]}], +["
{}
", + [["insertimage","/img/lion.svg"]], + ["
", + "

"], + [true], + {}], +["
{}
", + [["insertimage","/img/lion.svg"]], + ["
", + "

"], + [true], + {}], +["
{}
", + [["insertimage","/img/lion.svg"]], + ["
", + "

"], + [true], + {}], +["
A[]B
", + [["insertimage","/img/lion.svg"]], + "
AB
", + [true], + {}], +["
A[]B
", + [["insertimage","/img/lion.svg"]], + "
AB
", + [true], + {}], ]